I'd like to evaluate user input only where it makes sense, e.g.
"2*(3+2)" ==> 10
"2*dog" ==> "2*dog"
"mysquarefunction(2)" ==> 4
"3*mysquarefunction(2)" ==> 12
"some guy" ==> "some guy"
I've tried:
if ($val =~ m|[0-9]|) { $val = eval $val; }
and
{
no warnings;
eval { $val2 = eval $val };
if (!$@) { $val2 = $val; }
}
... but neither work on all of the examples above.
I'd really rather try the eval, and if it bonks, just use what they entered.
But I can't figure out how to keep perl from dumping a warning to STDOUT
when it bonks.
Is this possible?
- Bryan
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>