in reply to list context
Do the parentheses around $x do anything?It's one of the few cases where parenthesis actually create a list.
It seems to me that the rhs will always be a scalar,Actually, in this case, it isn't. The context of the RHS of an assignment is determined by the LHS. In fact, assignment in list context is a different operator from assignment in scalar context - although both of them are represented by the same symbol. The important thing is context. The context of an expression is always determined by the context (duh!), and never by the expression itself. If the LHS of an assignment is a list, the RHS is in list context, regardless of how the RHS looks like.
and these are equivalentThey are equivalent in the sense they print the same thing. Do you consider:
andmy $x = 3 - 1; say $x;
to be equivalent?my $y = length "ab"; say $y;
In your example, in the first case, $x gets the value of the scalar expression on the RHS of the assignment. In the second case, $y is assigned the value of the first element of the list on the RHS of the assignment. There's a difference. Whether you find the difference significant enough to call it not equivalent, or small enough to call it equivalent, I leave up to you. As long as you know what the difference is, it doesn't matter how you label it.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: list context
by ikegami (Patriarch) on Dec 07, 2010 at 00:29 UTC |