Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7050651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:10:09+00:00 2026-05-28T03:10:09+00:00

What are the arguments used in IO::Pipe perl constructors? What I see in documentation

  • 0

What are the arguments used in IO::Pipe perl constructors?

What I see in documentation is:

IO::Pipe::new optionally takes two arguments, which should be objects blessed into IO::Handle, or a subclass thereof. These two objects will be used for the system call to pipe. If no arguments are given then method handles is called on the new IO::Pipe object.

I don’t really get what it means. Can someone provide an example/explanation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:10:10+00:00Added an answer on May 28, 2026 at 3:10 am

    It’s straight-forward once you learn object-oriented programming. See the Stack Overflow archive for recommendations of appropriate teaching material. To follow the explanation below, you need to keep in mind that bless works not only on hashrefs.

    You should also already completely understand what the underlying pipe POSIX system call does, and what a file descriptor is in C and Perl and what all sort of things it can point to, and how a FD is passed around in Perl as a glob. If these pieces are confusing, too, open separate questions and reference this one.

    use IO::Pipe qw();
    my $pipe = IO::Pipe->new($reader, $writer);
    

    tl;dr version: $reader and $writer are expected to be file handles you or something else has opened earlier, most likely from the open function or a IO::File instance. The documentation mentions IO::Handle foremost because likely you want to also pipe FDs that are not proper files, but standard streams (STDIN, STDOUT) connected to certain processes, and for this purpose IO::Handle suffices.


    Detailed version:

    The $reader and $writer variables are expected to contain object instances of type IO::Handle ($reader is-a IO::Handle). IO::Handle is rarely used, more often its subclass IO::File.

    use IO::File qw();
    my $reader = IO::File->new('/usr/src/linux/COPYING', 'r');
    # bless(*Symbol::GEN0 => 'IO::File')
    $reader->fileno
    # 6
    $reader->can('getline')
    # true
    
    use IO::File::WithPath qw();
    my $writer = IO::File::WithPath->new('/tmp/foobar', 'w');
    $writer->fileno
    # 7
    $writer->can('print')
    # true
    

    For historical reasons, a lot of things that are not strict subclasses of IO::Handle work, too. It suffices that they merely behave like IO::Handle (“duck type”), i.e. provide some of the methods mentioned in the documentation, and those need not be inherited from IO::Handle.

    open my $other_reader, '<', '/usr/src/linux/COPYING';
    # \*{'::$other_reader'}
    $other_reader->fileno;
    # 8
    $other_reader->can('getline');
    # false, but works anyway, see http://p3rl.org/IO::Handle#BUGS
    
    use File::Temp qw(tempfile);
    my ($other_writer) = tempfile;
    # \*{'File::Temp::$fh'}
    $other_writer->fileno;
    # 9
    $other_writer->can('print')
    # false, but works anyway, see http://p3rl.org/IO::Handle#BUGS
    
    use IO::String qw();
    my $s = IO::String->new("foo\nbar\nbaz");
    # bless(*Symbol::GEN1 => 'IO::String')
    $s->fileno
    # undef
    $s->can('getline')
    # true
    
    ### TODO
    use File::Map qw(map_handle);
    map_handle my $map, '/boot/vmlinuz';  # ???
    
    ### TODO   some popen examples
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Many IDEs allow you to add some custom command line arguments which are used
I have the following code which forks two new processes to take the contents
I have a form post method, which is used to show a new page.
What numbers of arguments are used for main ? What variants of main definition
ArgumentException and ArgumentNullException are both used for validating arguments, eg. if (argument == null)
Trying to pass a string argument to a function, which will then be used
Validating Primitive Arguments and Complex Data Validating Arguments When writing a method, arguments should
I used this code which found on forum without errors in 4.0.2a and now
We all know MATLAB provides tab-completion for filenames used as arguments in MATLAB function
Can C-Style strings be used as template arguments? I tried: template <char *str> struct

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.