I'm trying to determine how Perl evaluates operands for expressions. I
expected the following code to output 3, 4, and 5, as it would if
executed as a C++ or Java program. The actual output that I get
(v5.16.2), however, is 4, 4, and 5. This leads me to believe that
operand evaluation is either non-deterministic and compiler-dependent,
or it's simply broken.
The Perl documentation discusses operator evaluation, but doesn't
directly address operand evaluation order. Does anyone know of a good
resource for this information?
Thanks,
Ralph
sub doit {
return ++$g ;
}
$g = 0;
my $sum = $g + doit() + doit();
print "$sum \n";
$g = 0;
$sum = doit() + $g + doit();
print "$sum \n";
$g = 0;
$sum = doit() + doit() + $g;
print "$sum \n";
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/