in reply to Re^3: Why? (each...)
in thread Why? (each...)
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)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Why? (each...)
by Argel (Prior) on May 12, 2011 at 23:15 UTC | |
by ikegami (Patriarch) on May 12, 2011 at 23:53 UTC | |
by LanX (Saint) on May 13, 2011 at 00:06 UTC | |
by ikegami (Patriarch) on May 13, 2011 at 00:13 UTC | |
by Argel (Prior) on May 13, 2011 at 18:37 UTC | |
|