Tay Ray Chuan <> wrote:
> Hi, I tried using eval like this:
>
> print "Enter something to evaluate:\n";
> while (defined($s = <>)) {
> $result = eval $s;
> if ($@) {
> print "Invalid string:\n $s";
> } else {
> print "$result\n";
> }
> }
>
> this can evaluate anything. but when I type this:
>
> "$a=5;$b=5;$c=$a+$b;print $c;", it prints "101".
>
> Why is there an extra "1"?
The last expression eval()uated is the value of the eval(), so
$result gets print()'s return value (1).
So, the
print $c
outputs the 10
then
print "$result\n";
outputs the 1 and a newline.
--
Tad McClellan SGML consulting
Perl programming
Fort Worth, Texas