[Chicago-talk] How to make readline <> block on pipe.

Warren Smith warren at warrenandrachel.com
Fri Sep 23 10:41:07 PDT 2005


Are you sure you have a pipe?

$ mkfifo bob
$ ping localhost -i 5 > bob &
$ perl -le 'open my $fh, "<", "bob"; print while <$fh>'

Works for me.

-Warren


Jon Amundsen wrote:

>Hi All!
>
>Does anyone know how to make the <> operator or readline block until there is data?  I am trying to read from a pipe, and would like it to block until more data arrives.
>
>Here is a simple example:
>
>
>open(APIPE, "<./pipe") || die $! ;	### the open *does* block
>
>while(1) {
>
>	my $line = <APIPE> ;		### if there's nothing on the pipe this doesn't wait.
>	print "line is: ", $line, "\n" ;
>	sleep 1 ;			### just so it doesn't spin too fast during testing
>
>}
>
>
>I've tried using IO::File also and the ->blocking() method, but as far as I can tell it behaves the same.  Any help is really appreciated.
>
>  
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Chicago-talk mailing list
>Chicago-talk at pm.org
>http://mail.pm.org/mailman/listinfo/chicago-talk
>



More information about the Chicago-talk mailing list