($foo) = (7,2,4); # list context - comma := list separator print $foo,"\n"; __END__ 7
$foo = (7,2,4); # scalar context despite of parens - comma := 'C' co +mma print $foo,"\n"; __END__ 4
$foo = (7,2,4) x 3; # comma := 'C' comma, 'x' operates on scalar print $foo,"\n"; __END__ 444
@foo = (7,2,4) x 3; # comma := list separator, 'x' operates on list print @foo,"\n"; __END__ 724724724
Parens are just grouping, thus for precedence. They do not provide list context. The list context in
@foo = (7,2,4);
is enforced by the LHS of the expression. But it is perfectly legal to assign a single scalar to an array. The parens are for precedence first, and then, that being clear, the comma is disambiguated as a list separator, as enforced by the LHS.
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
In reply to Re^3: array assignment with list operator , no parenthesis
by shmem
in thread array assignment with list operator , no parenthesis
by jesuashok
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |