Weizhong Dai <weizhong....@gmail.com> asked: > --------------------------------- > $pid = open(README, "program arguments |") or die "Couldn't fork: > $!\n"; > while (<README>) { > # ... > } > close(README) > ---------------------------------- > > my problem is: I read from README, but if waiting for next input is > timeout, end reading. Is there any timer or method I could use for > this purpose?
This code is probably better written as my $program = ...; my @arguments = ...; my $pid = open( my $readme, '-|', $program, @arguments) or die "Can't fork '$program': $!"; while( <$readme> ){ ... } close( $readme ); (code OTTOH, please excuse any typos) i.e. - use lexical variables - don't use a typeglob for your filehandle, use a lexical variable instead - use three-argument open for increased safety As for the timeout question, I assume what you want to do is this: - read input from $program - if there's no input, then stop reading after suitable timeout period Something like that is usually done using select() as shown in the second usage example in http://perldoc.perl.org/functions/select.html HTH, Thomas -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/