Not tested, but should get you pointed in the right direction. Alarm 0 is important to unset the alarm.$SIG{ALRM} = sub {die 'timeout'}; while ( $number < 10 ) { eval { alarm(3); print $number; if ( $number == 3 ) { sleep 4; } # This is to simulate the delay + the routines may generate... $number++; print "\n"; }; alarm(0); if($@ eq 'timeout') { next; } else { die $@; } }
In reply to Re: How to timeout a while loop?
by suaveant
in thread How to timeout a while loop?
by Andre_br
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |