Quote:
Originally Posted by qsecofr
Code:
# put some code inside $str
$str = '$c = $a + $b'; # Perl doesn't care what's inside $str
$a = 10; $b = 20;
eval $str; # Treat $str as code, and execute it.
print $c; # prints 30
|
Although I can only assume that you are responsible for the veracity of the code inserted into the database, it would still be prudent to check the value of
$@ after the
eval statement to ensure that the string executes without error.
Likewise, it is better to find out
early that an error has occurred rather than wait until later when the culprit has been masked many times over.