in reply to using eval
The eval you're using, eval { ... }; is called a block eval. It catches exceptions (die statements), it does not evaluate the contents of the variables as Perl code. The eval you want is a string eval, $answer = eval $question;.
You should also realize that these must be valid Perl expressions, and they use the Perl operators. x^4-3 xors the string "x" with 4, then subtracts 3; you probably meant $x ** 4 - 3, but that requires $x be defined.
For further details please see eval and perlop. I also have a script that evaluates code entered in on the command line called math.
|
|---|