We don't bite newbies here... much | |
PerlMonks |
Re: Re: What is a pipe and why would I want to use one?by rjray (Chaplain) |
on Jul 10, 2002 at 09:12 UTC ( [id://180706]=note: print w/replies, xml ) | Need Help?? |
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 Section
Seekers of Perl Wisdom
|
|