in reply to Re: Parsing Math Strings
in thread Parsing Math Strings

So the solution would be:
#You might want to do something to look for say sin, cos, tan, etc. unless( $str =~ /[^0-9+-*^/.,_()]/ ){ eval($str); }

--
perl -p -e "s/(?:\w);([st])/'\$1/mg"

Replies are listed 'Best First'.
Re: Re: Re: Parsing Math Strings
by Fastolfe (Vicar) on Dec 07, 2001 at 00:08 UTC
    Or use the Safe module and mask the operators that can be considered potentially harmful. This has the benefit of allowing the "math expression" to be arbitrarily complex (Perl, really), and if you pre-loaded things like Math::Complex, you could potentially have a very powerful "calculator."
      /me always forgets Safe (and Penguin)

      --
      perl -p -e "s/(?:\w);([st])/'\$1/mg"