Using open to create the pipe for you in this fashion does in fact execute the child program, yes.

There are no environment variables involved, so none of your examples are exactly correct. When Kiddy.pl starts, it will have a STDIN that is not connected to the TTY, like Daddy.pl has. Instead, STDIN is like any other filehandle (which it is, anyway). You read from it with "$line = <STDIN>" just as you would with any other filehandle. Whatever the Daddy.pl writed to SEND, Kiddy.pl reads from STDIN.

Your third example is close, though. What it would do is run a separate execution of Daddy.pl when you manually ran Kiddy.pl. Then, whatever Daddy.pl wrote to STDOUT, Kiddy.pl would read from GET.

One last thing worth noting: if your program wants to know if a given filehandle is a pipe, you can test it with the -p file-test operator:

my $is_a_pipe = -p STDIN;

This is very useful when testing if the program is writing to a pipe-- if it is, you may choose to format data differently, or if you were pausing at page breaks you would choose not to, etc.

--rjray


In reply to Re: Re: What is a pipe and why would I want to use one? by rjray
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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.