eval without warnings
- From: Bryan_R_Harris@xxxxxxxxxxxx (Bryan R Harris)
- Date: Tue, 27 Sep 2005 16:42:03 -0700
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
.
- Follow-Ups:
- Re: eval without warnings
- From: Jeff 'japhy' Pinyan
- Re: eval without warnings
- From: Chris Devers
- Re: eval without warnings
- Prev by Date: Re: Shift Question
- Next by Date: Re: general retry function
- Previous by thread: general retry function
- Next by thread: Re: eval without warnings
- Index(es):
Relevant Pages
|