Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Pipe dream

by Zaxo (Archbishop)
on Sep 09, 2005 at 10:09 UTC ( [id://490495]=note: print w/replies, xml ) Need Help??


in reply to Pipe dream

There is pipe. Pipe is lower level than shell pipes so is more flexible. It is possible to set up arbitrary networks of processes with pipe, fork, and select. The complexity of such things prevents their use, but that is not a limit of Perl.

It is pretty easy to set up a coprocess which you can print stuff to, and read back the result. Skeletal version:

my ($pin,$pout,$cin,$cout,%kid); { pipe $pin, $cout; pipe $cin, $pout; my $cpid = fork; die $! unless defined $cpid; $kid{$cpid} = 1, last if $cpid; # parent close $pin or die $!; # in child to end of block close $pout or die $!; while (<$cin>) { # do filter-like stuff to $_ print $cout $_; } exit 0; } # parent close $cin or die $!; close $cout or die $!; # print to $pout and read from $pin, maybe in a select loop # depends on expected behavior of the child. delete $kid{wait()} while %kid;
The complication of that could be wrapped in a module, and probably has been.

After Compline,
Zaxo

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://490495]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2025-07-19 07:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.