# setup an ALRM handler my $timed_out = 0; local $SIG{ALRM} = sub { die "Timed out!" }; # run some code for 10 seconds max eval { alarm 10; # let it run 10 seconds eval($code); die $@ if $@; }; # figure out if it got an alarm warn "Alarm rang!" if $@ and $@ =~ /Timed out!/;
However, an infinitely running regex would probably not get interupted here due to Perl's new safe-signals implementation which only looks for new signals between op-codes.
-sam
In reply to Re: Stopping code in eval
by samtregar
in thread Stopping code in eval
by Outaspace
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |