Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Stopping code in eval

by liz (Monsignor)
on Jul 20, 2006 at 18:19 UTC ( #562662=note: print w/ replies, xml ) Need Help??


in reply to Stopping code in eval

If your only worry is about recursing too deeply, you could do something like this:

eval { use warnings 'recursion'; local $SIG{__WARN__} = sub { die "Too deep" if $_[0] =~ m#^Deep re +cursion# }; # your code }; # check $@ if you want to here
One of Perl's nice features is that it can actually output a warning when you're recursing too deeply (for whatever Perl considers to be "too deeply"). This trick changes that warning into an exit condition. This is a very simple case, if you need to keep the normal __WARN__ handler behaviour, things get a little more complicated.

Hope this helps.

Liz


Comment on Re: Stopping code in eval
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://562662]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2015-07-05 20:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (68 votes), past polls