[San-Diego-pm] Module idea for input/output multiplexing

Emile Aben emileaben at gmail.com
Mon Dec 11 22:48:36 PST 2006


Module idea from discussion at the meeting tonight:
A module that hooks up stdout from one process with the stdin of
several other processes,
or maybe more generic: Something that reads from a filehandle and
writes that output to
several other filehandles.

Simple example of use:
reading a gzipped file from disk, and calculating the md5 (using md5,
md5sum or 'openssl md5' command, depending on your OS) and linecount
(wc -l) **

I've looked into IPC::Run a bit, and IPC::Run might be able to do
something like this, but
the best I've been able to come up with this far doesn't work:
#!/usr/bin/env perl
use Carp;
use strict;
use warnings;
use IPC::Run qw(run);

my $cat_cmd = ['cat'];
my $md5_cmd = ['/usr/bin/openssl','md5'];
my $wc_cmd = ['wc','-l'];

my $md5_out = undef;
my $wc_out = undef;

run($cat_cmd,'<',"$0", '>&3', '>&4',
  '3>pipe', $md5_cmd, '>', \$md5_out,
  '4>pipe', $wc_cmd,   '>', \$wc_out);

print "linecount: $wc_out\n";
which produces errors:
Not a GLOB reference at /usr/lib/perl5/site_perl/5.8.3/IPC/Run/IO.pm line 329.
Not a GLOB reference at /usr/lib/perl5/site_perl/5.8.3/IPC/Run/IO.pm line 329.

or under perl -d:
called at /usr/lib/perl5/site_perl/5.8.3/IPC/Run.pm line 1434
called at ./ipcrun.pl line 14

that's enough for me tonight.


** both calculating md5 and linecount can be done in perl as well of
course, but that's not the point here

More information about the San-Diego-pm mailing list