The important thing to understand (and something that I clearly misunderstood ten years ago -- I still remember the feeling of egg on face) is that there simply is no such thing as a list in scalar context. A "list producing expression used in scalar context" does not produce a list. It just produces a single value, which is the last element in the comma-delimited expression. (That's as near as I can come to describing the right-hand-side.)
So the truth is that this construct:
my $a = ( 10, 20, 30, 40, 50 );
...is not generating a list in scalar context and then assigning the last element to $a. It's assigning the scalar value 50 to $a, that's it. There's no list, and the entity has a size of one.
B::Deparse's output is interesting when list-producing syntax is used in scalar context. There's no list. :)
perl -MO=Deparse -E '$x = (10,20,30); say $x'
There you'll see the comma operator at work doing what it's supposed to do in scalar context: throwing away the item on the lefthand, returning the one on the right.
Dave
In reply to Re: Return Value of List-Producing Elements in Scalar Context
by davido
in thread Return Value of List-Producing Elements in Scalar Context
by pikus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |