M
Mad Scientist Jr
I seem to be getting a syntax error when evaluating expressions with
Eval.
(Also, can someone show what the right way to trap the error is?)
Much appreciated...
#THIS WORKED:
if (1==2) {$answer1='answer1 evaluates to true';} else
{$answer1='answer1 evaluates to false';}
if (2==2) {$answer2='answer2 evaluates to true';} else
{$answer2='answer2 evaluates to false';}
print $answer1;
print $answer2;
#WHEN WE PUT THE ABOVE INSIDE 'EVAL' WE GET A SYNTAX ERROR:
$str = "if (1==2) {$answer1='answer1 evaluates to true';} else
{$answer1='answer1 evaluates to false';}";
eval $str;
$str = "if (2==2) {$answer2='answer2 evaluates to true';} else
{$answer2='answer2 evaluates to false';}";
eval $str;
print $answer1;
print $answer2;
#AFTER WE GET THE SIMPLE ONE WORKING WE'LL TRY THIS
#WE PROBABLY HAVE TO CONVERT THE OPERATORS TO PERL IE == NE GT ETC.
#$str = "if ( (17 >= 21) or (6.6 > 6.5) ) and (\"Bob\" <> \"leon\") and
(FALSE = false)";
Eval.
(Also, can someone show what the right way to trap the error is?)
Much appreciated...
#THIS WORKED:
if (1==2) {$answer1='answer1 evaluates to true';} else
{$answer1='answer1 evaluates to false';}
if (2==2) {$answer2='answer2 evaluates to true';} else
{$answer2='answer2 evaluates to false';}
print $answer1;
print $answer2;
#WHEN WE PUT THE ABOVE INSIDE 'EVAL' WE GET A SYNTAX ERROR:
$str = "if (1==2) {$answer1='answer1 evaluates to true';} else
{$answer1='answer1 evaluates to false';}";
eval $str;
$str = "if (2==2) {$answer2='answer2 evaluates to true';} else
{$answer2='answer2 evaluates to false';}";
eval $str;
print $answer1;
print $answer2;
#AFTER WE GET THE SIMPLE ONE WORKING WE'LL TRY THIS
#WE PROBABLY HAVE TO CONVERT THE OPERATORS TO PERL IE == NE GT ETC.
#$str = "if ( (17 >= 21) or (6.6 > 6.5) ) and (\"Bob\" <> \"leon\") and
(FALSE = false)";