sub Gets { my($fh, $timeout) = @_; my($str, $c, $rin, $rout, $found, $timeleft); $rin = ''; vec($rin, fileno($fh), 1) = 1; $timeout ||= 1; while (1) { ($found, $timeleft) = select($rout=$rin, undef, undef, $timeout); last unless $found; sysread($fh, $c, 1); $str .= $c if ($c ne "\0"); last if ($c eq "\n"); } return $str; }