According to Perldoc( https://perldoc.perl.org/perlop#Comma-Operator ):
Comma Operator
...
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.
In following code, I thought $n should be 1 but it became 2. What am I missing?
my $v = 1;
my $n = ( $v, $v = 2 )[0];
# I thought left "$v" would be evaluated (and return 1) first, then right "$v = 2" would.
say "n = $n"; # but output was 2
say "v = $v"; # 2
or
my $v = 1;
my @l = ( $v, $v = 2 );
say Dumper(\@l); # [ 2, 2 ], not [ 1, 2 ]
even when I changed the order:
my $v = 1;
# my $n = ( $v, $v = 2 )[0];
my $n = ( $v = 2, $v )[1];
say "n = $n"; # still 2
say "v = $v"; # 2