[boulder.pm] Reading from a pipe with strict?
Robert L. Harris
Robert.L.Harris at rdlg.net
Tue Mar 27 17:29:08 CST 2001
Know much about IO::Select and reading from it? I have this:
while ($KeepGoing eq "T") {
my ($sel) = new IO::Select( \*READER );
while(@PipeReady = $sel->can_read(5)) {
foreach $FileHandle (@PipeReady) {
if ($FileHandle == \*READER) {
# We have something to read....
@LinesFromReader=<\*READER>;
print "\@LinesFromReader :@LinesFromReader:\n" if ($Verbose eq "T");
foreach $tmp ( @LinesFromReader ) {
#Process our lines
if ( $tmp =~ /^Ripper/) {
# Do something if output from child starts with "Ripper"
} elsif ($tmp =~ /^Encoder/) {
# Do something if output from child starts with "Encoder"
}
}
}
}
}
&DoSomeOtherStuffIndependantly;
}
It's all working nicely except when the pipe actually returns something
and should go to the line with ^Ripper or ^Encoder. Then the
print "\@LinesFromReader.... just prints alot of blank lines and
doesn't quit as if it's not getting EOF from the dying child.
$KeepGoing is set to F in the DoSomeOtherStuffIndependantly....
This is all kind of pieced together from what I've read here, there
and everywhere. If someone has a good optimization, or such to repace
the read, please speak up.
Robert
Thus spake Martin Lichtin (lichtin at bivio.com):
> The * is the typeglob prefix, it makes it possible to pass
> filehandles to subroutines. The \ converts it into a reference.
>
> Check out the perlsub manual page, where it says:
>
> If you're passing around filehandles, you could usually just use
> the bare typeglob, like *STDOUT, but typeglobs references would be
> better because they'll still work properly under use strict 'refs'.
> For example:
>
> splutter(\*STDOUT);
> sub splutter {
> my $fh = shift;
> print $fh "her um well a hmmm\n";
> }
:wq!
---------------------------------------------------------------------------
Robert L. Harris | Micros~1 :
Senior System Engineer | For when quality, reliability
at RnD Consulting | and security just aren't
\_ that important!
DISCLAIMER:
These are MY OPINIONS ALONE. I speak for no-one else.
FYI:
perl -e 'print $i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);'
More information about the Boulder-pm
mailing list