|
Posted by Jürgen Exner on July 23, 2008, 10:50 am
Please log in for more thread options >At 2008-07-23 12:36AM, "syang8" wrote:
>> Is there any peal script available that I can quickly calculate a
>> string " (3+5)*5/40 " or " 4*7-7*(4+5) " ? There are only the digits
>> and +,-,*,/ and () available in the string. Thank you!
>
> $str =~ m and $result = eval $1;
>
>This does not check that your expression is "well formed" (e.g. $str="1+")
Yes, it does:
If there is a syntax error or runtime error, [...],
an undefined value is returned by "eval", [...]
The code doesn't doesn't do any error handling, but that's a different
animal.
jue
|