I'm curious about the behavior of the scalar value of a list assignment expression,
sub foo { my ($a) = qw(first second third); }; printf "in scalar context: %s\n", scalar foo(); printf "in list context: %s\n", join ',', foo();
This gives me,
in scalar context: 3 in list context: first
So it seems like the value of a list assignment in scalar context is the scalar-context value of the list on the right-hand side of the assignment, but the value of the list assignment in list context is the list-context value of list on the left-hand side of the assignment.
Is that correct? Is there a simpler way of putting that?
This is sort of a surprising result. I expected the list and scalar context values to "match", or come from the same place, but in this case it appears they come from different parts of the expression (left-hand/right-hand sides).
In reply to scalar value of list assignment by tantalor
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |