This probably belongs on perlmonks or a newgroup, but this site is my primary interface into the Perl community. I'm debating submitting this as an ask use Perl;.
I need to read from arbitrary filehandles with a timeout, i.e., timed_read($fh, 2) reads from the filehandle in $fh but if nothing is received in 2 seconds the call is interrupted and you return with an undef. Now, you're thinking $SIG{ALRM}, but I can't do that. I've already got alarms going for something else, and I might need resolution other than integral seconds.
Expect (the TCL version) comes with a timed-read command-line script that accomplishes this very nicely. I won't have expect on the machine I'm using, though, and besides, I want to do this in pure Perl. The way it's accomplished there is with the select() system call. I'm working to do the same thing in Perl, and it seems to sort of work.
What's the right way to be doing this? Is there a module for timed reads? Is there a FAQ entry somewhere I've missed? My version with select() doesn't work reliably at the moment, and I'm hoping to find someone else has already invented this wheel.
As for timed reads, is Time::HiRes what you're looking for?*
* both on CPAN