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

Reading from multiple pipes

Thread Next
From:
Ed Avis
Date:
September 30, 2009 08:36
Subject:
Reading from multiple pipes
Message ID:
loom.20090930T173558-928@post.gmane.org
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 <eda@waniasset.com>


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About