In the current context, they definitely do NOT create a list. They override the relative precedence of the comma and assignment operators.
my %keys = (A => "b"); - --- 1 2 List has two items
my %keys = A => "b"; ------------ --- 1 2 List still there without parens
Parens never create a list as far as I'm concerned, but people have debated me on two specific cases:
In some places where a list is already being created, «()» is needed to indicate the list contains no elements. The parens don't create the list (since it would also get created if one used «@a» instead of «()»), they simply indicate the list is empty.
In some places, the presence of parens affect the choice of operator to one that creates a list. (e.g. «$x = f();» vs «($x) = f();»). It's actually the assignment operator (not the parens) that creates the list as is gets created for «@a = f();» as well. Although both indirectly create a list, it makes no sense to say that parens create a list since noone says "«@a» creates a list".
Parens, curlies and square brackets have other uses than those I described, of course, but I doubt the other uses create confusion.
Lists value are created by operators that always take a list (e.g. foreach, list assignment, function calls, etc), and list literals are created by the comma operator.
foreach ($x) { } @a = @b; f $x; ^^ ^^ ^^ ^^ list list list list value value value value $i, $j; @a = ($i, $j); ^^^^^^ ^^ ^^^^^^^^ list list list value literal value (from list literal)
In reply to Re^4: Why? (each...)
by ikegami
in thread Why? (each...)
by locked_user sundialsvc4
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |