use alarm function and catch SIG{ALRM} signal
sub some_sub { eval { local $SIG{ALRM} = sub {die "died in SIG ALRM";}; alarm(1); my $i=0; $i++ while 1; alarm(0); }; if ($@) { if ($@ =~ /died in SIG ALRM/) { print "caught\n"; } else { print $@; } } }
In reply to Re: Running code a certain amount of time
by ccn
in thread Running code a certain amount of time
by Ninth Prince
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |