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
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