in reply to Re: How to timeout a while loop?
in thread How to timeout a while loop?
Great! Thanks a lot; in fact i needed to change some details for it to work, like putting the sub that listens the $@ outside the while, but now it is just perfect.
Here´s the final code, for the monk's record:
Thanks a lot, my friendmy $number = 0; $SIG{ALRM} = sub {die 'timeout'}; while ( $number < 10 ) { eval { $number++; alarm(3); if ( $number == 3 ) { sleep 4; } # This is to simulate the delay + the routines may generate... print $number; print "\n"; }; alarm(0); } if($@ eq 'timeout') { next; } else { die $@; }
Andre_br
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: How to timeout a while loop?
by suaveant (Parson) on Apr 25, 2005 at 20:47 UTC |