[Chicago-talk] How to make readline <> block on pipe.
Jon Amundsen
jamundsen at jamundsen.dyndns.org
Fri Sep 23 11:24:32 PDT 2005
Thanks for the response.
On Fri, Sep 23, 2005 at 12:41:07PM -0500, Warren Smith wrote:
> Are you sure you have a pipe?
Yes I did!
>
> $ mkfifo bob
> $ ping localhost -i 5 > bob &
> $ perl -le 'open my $fh, "<", "bob"; print while <$fh>'
>
> Works for me.
And me as well. :) At this point I'm not even sure what wasn't working. It's been a long week. Sorry for the noise. :P
>
> -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.
> >
--
Jon Amundsen
jamundsen at jamundsen.dyndns.org
A "No" uttered from deepest conviction is better and greater than a
"Yes" merely uttered to please, or what is worse, to avoid trouble.
-- Mahatma Gandhi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://mail.pm.org/pipermail/chicago-talk/attachments/20050923/5beba348/attachment.bin
More information about the Chicago-talk
mailing list