On May 11, 12:56 am, weizhong....@gmail.com (Weizhong Dai) wrote:
> Hi all,
>
> ---------------------------------
> $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?
>
> thanks.

perldoc -q timeout
perldoc perlipc

Here's an example with a 5 second timeout:

$pid = open(my $readme, "program arguments |")
                  or die "Couldn't fork: $!\n";
my $timeout = 5;
eval {
    local $SIG{ALRM} = sub { die "timeout"; };
    alarm( $timeout );
    print while <$readme>;
    alarm(0);
    1;
}  or die "eval error: $@ ";
...

--
Charles DeRykus


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to