On Mon, 25 Nov 2002 11:34:23 +0000 (GMT), [EMAIL PROTECTED] wrote:
>>      $i = 20;
>>      my($x, $y, $z) = ($i++, $i, $i++);
>
>Now, it appears that perl's evaluation order is accident rather than
>design - so you SHOULD NOT rely on it.  Avoid causing side-effects on
>variables you use more than once... including the multiple use of shift
>in assignment.

This isn't an issue of evaluation order.  In the example above, perl
evaluates first $i++, then $i, then $i++, placing the results in a
list.  Then the assignment is done.  The reason $y becomes 22 is that
the *variable* $i is in the list (by reference, if you will), not the
*value* of $i.  Only when the assignment is done is the value
accessed.

Keep in mind that perl passes parameters by reference, and almost all
operands act just like subroutine parameters.  If you have:

sub aassign{ print "\$_[$_] is $_[$_]\n" for 0..$#_ }
$i = 20;
aassign($i++, $i, $i++)

you get:

$_[0] is 20
$_[1] is 22
$_[2] is 21

Reply via email to