http://qs1969.pair.com?node_id=293088


in reply to enforce timeout in loop

Follow the example in the perldoc page for alarm. Change your for loop to look like:
foreach my $sleepval (@sleepvals) { eval { local $SIG{ALRM} = sub { die }; alarm 3; sleep($sleepval); }; print strftime "%H:%M:%S", localtime; print "\n"; }

Replies are listed 'Best First'.
Re: Re: enforce timeout in loop
by semio (Friar) on Sep 22, 2003 at 15:48 UTC
    ++perlmonkey. beautiful. This is exactly what I was looking for.

    cheers, -dave