in reply to Re^2: Why does the first $c evaluate to the incremented value in [$c, $c += $_] ?
in thread Why does the first $c evaluate to the incremented value in [$c, $c += $_] ?
Well, quote-like operators have higher precedence than +=, so your example can still be explained by the "sub-expressions with higher-precedence operators are evaluated first" rule.
and also here result is 3 3:my $c = 2; my @a = ($c+0, $c+=1); print "@a"; __END__ 2 3
my $c = 2; my @a = ($c+=1, "$c"); print "@a"; __END__ 3 3
my $c = 2; my @a = ($c+=2, $c+=1); print "@a"; __END__ 5 5
my $c = 2; my @a = ($c+=1, $c+=2); print "@a"; __END__ 5 5
from perlop (about comma):my $c = 2; my @a = (($c), ($c+=1)); print "@a"; __END__ 3 3
In list context, it's just the list argument separator, and inserts both its arguments into the list. These arguments are also evaluated from left to right.
|
|---|