develooper Front page | perl.beginners | Postings from September 2009

Reading from multiple pipes

Thread Next
Ed Avis
September 30, 2009 08:36
Reading from multiple pipes
Message ID:
I'd like to fork several child processes and read lines from each, for example:

    open my $fh_foo, '-|', 'yes', 'foo' or die $!;
    open my $fh_bar, '-|', 'yes', 'bar' or die $!;
    while (<$fh_foo> OR <$fh_bar>) {               # magic happens here
        say "got a line from one of them: $_";

Is there a CPAN module or well-known recipe that can provide the necessary
magic to poll both filehandles and read a line from either?

If not, I will write something using select() and sysread(), but I wondered
if there was some more convenient way to do it.

Ed Avis <>

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About