Perl Monk, Perl Meditation | |
PerlMonks |
Re: Untitled questionby ahunter (Monk) |
on Jul 05, 2000 at 21:45 UTC ( [id://21170]=note: print w/replies, xml ) | Need Help?? |
Hmm, the buffering problems outlined in my select tutorial (here)
also apply to open2, and indeed any other type of file
that can block. If you're reading from multiple files,
you can use the Multiplex package presented there (and
you can use it to implement timeouts, too). Use sysread
and syswrite to write to the filehandles returned by
open2 (if you're only reading from one filehandle, you
don't really need the complexities of using select, and
$SIG{ALRM} will let you interrupt something that's blocking)
Setting the filehandle to nonblocking is probably not the answer to this, but it may help with the buffering problem. If you do set the nonblocking flag, use select to avoid having to poll the filehandle. Use sysread to read one byte at a time, or set the filehandle nonblocking and read (say) 256 at a time, but use select to wait for more to arrive. Andrew. (Hrm, I think untitled nodes should be given default names so we can click on them in newest nodes)
In Section
Seekers of Perl Wisdom
|
|