Re: eval without warnings

2005-09-28 Thread Bryan R Harris
> On Sep 27, Bryan R Harris said: > >> "2*(3+2)" ==> 10 >> "2*dog" ==> "2*dog" >> "mysquarefunction(2)" ==> 4 >> "3*mysquarefunction(2)" ==> 12 >> "some guy" ==> "some guy" > > Here's a solution that works for the cases you've provided: > >sub try_eval { > local $@; > my $warning

Re: eval without warnings

2005-09-27 Thread Jeff 'japhy' Pinyan
On Sep 27, Bryan R Harris said: "2*(3+2)" ==> 10 "2*dog" ==> "2*dog" "mysquarefunction(2)" ==> 4 "3*mysquarefunction(2)" ==> 12 "some guy" ==> "some guy" Here's a solution that works for the cases you've provided: sub try_eval { local $@; my $warning; local $SIG{__WARN__} = sub

Re: eval without warnings

2005-09-27 Thread Bryan R Harris
> On Tue, 27 Sep 2005, Bryan R Harris wrote: > >> 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" > > What happens when they put somethin

Re: eval without warnings

2005-09-27 Thread Chris Devers
On Tue, 27 Sep 2005, Bryan R Harris wrote: > 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" What happens when they put something in like "sys

eval without warnings

2005-09-27 Thread Bryan R Harris
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 = eva