Do you know where your variables are? | |
PerlMonks |
Re: Need pipe and parameter helpby shmem (Chancellor) |
on Nov 17, 2016 at 09:22 UTC ( [id://1176048]=note: print w/replies, xml ) | Need Help?? |
1) read a pipe and read parameters at the same time Paramters of the command line are accessible through the @ARGV array. If you want read from STDIN only, use <STDIN> like so:
which invoking $ ( echo Hi; sleep 3; echo Bye ) | ./ReadAPipe.pl 1 2 3 4 produces
2) not hang if the pipe is empty
Except for buffering by the OS, pipes are always empty - this is how pipes work. Writing to a pipe blocks the writer, as long as the reader doesn't read. Reading from the pipe blocks the reader, as long as the writer doesn't write. If the writer closes the pipe, the reader gets end-of-file (eof). If you want the reader to time out, you might set up an alarm handler
- note that the Bye line is missing due to timeout - or you could use select or IO::Select which provides a nice interface to select.
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
In Section
Seekers of Perl Wisdom
|
|