in reply to Parsing Math Strings
The better solution is to selectively use eval. Set up a hash that will store variable values. Use a regex to translate 'bare' variables in your expressions to point to this hash. Then eval the expression as necessary:
my $exp = "y=2*x+3"; my %vars = ( x => 1 ); $exp =~ s/([a-z]+)/\$vars{\1}/g; eval $exp; print $vars{ y };
-----------------------------------------------------
Dr. Michael K. Neylon - mneylon-pm@masemware.com
||
"You've left the lens cap of your mind on again, Pinky" - The Brain
"I can see my house from here!"
It's not what you know, but knowing how to find it if you don't know that's important
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Parsing Math Strings
by japhy (Canon) on Dec 06, 2001 at 20:46 UTC | |
|
Re: Re: Parsing Math Strings
by Zaxo (Archbishop) on Dec 07, 2001 at 06:52 UTC |