in reply to eval order of args to a sub
Perl evaluates the arguments from left to right (according to the associtivity of the list seperator).
>perl -le"$i=3; print($i+0, ++$i, $i+0);" 344
However, because Perl passes all arguments by reference, the order of operation sometimes *appears* unclear.
>perl -le"$i=3; print($i, ++$i, $i);" 444
The first snippet is similar to
# $i=3; print($i+0, ++$i, $i+0); $i = 3; do { local @_; $anon0 = $i+0; alias $_[0] = $anon0; $i = $i+1; alias $_[1] = $i; $anon1 = $i+0; alias $_[2] = $anon1; &print };
The second snippet is similar to
# $i=3; print($i, ++$i, $i); $i = 3; do { local @_; $i; alias $_[0] = $i; $i = $i+1; alias $_[1] = $i; $i; alias $_[2] = $i; &print };
Can you guess what the following prints?
perl -le"$i=3; sub { $_[1]++; print @_ }->($i+0, ++$i, $i+0, $i);"
In Section
Seekers of Perl Wisdom