Give local higher precedence
>perl -le"$x=2; { (local $x)=$x; print $x; $x=3; print $x } print $x"
2
3
2
Give assignment higher precedence
>perl -le"$x=2; { local ($x=$x); print $x; $x=3; print $x } print $x"
2
3
3 <-- XXX
I also see that '=' evaluates it's right side 1st.
Where did you see this? Operand evaluation order determines which operand is evaluated first. The operand evaluation order for = and other Perl binary operators is not documented anywhere and should probably be considered undefined.
Perhaps you looked up the associativity of the = operator. Associativity doesn't define which operand is evaluated first, it determines which operator is evaluated first when two operators of the same precedence are chained.
However, you are right that this feature of my and local is implemented by choosing a right to left operand evaluation order for assignment operators.
>perl -le"local(${print('a'), 'x'}) = ${print('b'), 'x'};
b
a
Updated: Updated code into "precedence is irrelevant" reply.
|