Beefy Boxes and Bandwidth Generously Provided by pair Networks kudra
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
A pipe is a form of Inter-Process Communication or IPC. Think of it as an actual pipe that takes the output of a process and "pipes it" to the input of another process.

In most operating systems that support this mechanism, the pipes are implemented as file descriptors that one of the processes writes to and the other, reads from.

Pipes are very useful in producer - consumer problems. In Unix you'll see a lot of that, when you need to combine two commands to perform a particular action. For instance, in order to get the list of files in your current directory, sorted by lexicographical order, you would issue the following shell command:

ls | sort

When handling this command, the shell will arrange for the process "ls" to run, sending its output to a pipe and the process "sort" to take its input from the same pipe. Therefore, every byte produced by the "ls" command will be eventually read and processed by "sort".

Perl has the capability to use pipes. It can automatically send your program's output to a pipeline by saying something like

open(FHANDLE, "| sort")

Or get input from a pipeline, such as in

open(FHANDLE, "ls |")

You also have "low level" control of the pipes. You can create a pipe, fork() and use it to keep father and child (or siblings or whatever) happily talking to each other. The call to do this is (surprisingly) called pipe. See perldoc for more details and perlipc for an excellent tutorial on the different forms of IPC available on Perl.

Hope this helps.


In reply to Re: What is a pipe and why would I want to use one? by fokat
in thread What is a pipe and why would I want to use one? by whiteperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (9)
    As of 2014-04-23 22:42 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (556 votes), past polls