|
|
|
Your skill will accomplish what the force of many cannot |
|
| PerlMonks |
capture errors from evalby sdetweil (Sexton) |
| on Sep 23, 2012 at 20:50 UTC ( #995250=perlquestion: print w/ replies, xml ) | Need Help?? |
|
sdetweil has asked for the
wisdom of the Perl Monks concerning the following question:
I'm back again..
in prior topics I discussed a section of my code that allows my users to execute an arbitrary regular expression using eval $w; where $w contains the expression.. but, if they code it wrong, my application dies. for example, expression= '/HOST=.*(' will yield a fatal die error.. Unmatched ( in regex; marked by <-- HERE in but I don't want it to be fatal.. the contents of $w is (no quotes) '$expdata =~ /HOST=.*(;' but eval {$w;} is ignored --- from the perl content on eval eval '$x'; # CASE 3 eval { $x }; # CASE 4 Cases 3 and 4 likewise behave in the same way: they run the code '$x', which does nothing but return the value of $x. --- and I can confirm that the expression itself does not execute. So.. is there some trick to this? thanks
Back to
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||||