Tom Phoenix wrote:
On 10/19/06, Norbert Preining <[EMAIL PROTECTED]> wrote:

$b = (++$a) + ($a++);

I'm not sure whether C does so, but I believe that Perl does NOT
promise that auto-increments will be executed in the "expected"
left-to-right order. Thus, if a single expression includes more than
one auto-increment working on the same variable, generally you can't
be sure what Perl will do with it. As you found.

Did this come up in a real-world situation, or were you specifically
seeking to test the limits of Perl? In other words, what problem, if
any, are you trying to solve?

I think it's academic Tom, and it's caught my interest!

The order of evaluation is immaterial, look:

$a = 3;
$b = 0;
$b += ++$a;         # Now $a == 4, $b == 4
$b += $a++;         # Now $a == 5, $b == 8

$a = 3;
$b = 0;
$b += $a++;         # Now $a == 4, $b == 3
$b += ++$a;         # Now $a == 5, $b == 8


so the final values of $a and $b are the same regardless and Perl is definitely
doing something wrongly in the single-line version. Although it's clearly not
a very important thing since it's managed to remain unfixed since at least
v5.6 if not before!

Cheers,

Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to