in reply to Return Value of List-Producing Elements in Scalar Context
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Return Value of List-Producing Elements in Scalar Context
by LanX (Saint) on Jul 28, 2013 at 14:26 UTC | |
by AnomalousMonk (Archbishop) on Jul 28, 2013 at 15:21 UTC | |
by LanX (Saint) on Jul 28, 2013 at 18:09 UTC | |
|
Re^2: Return Value of List-Producing Elements in Scalar Context
by Anonymous Monk on Jul 28, 2013 at 03:57 UTC | |
by davido (Cardinal) on Jul 28, 2013 at 05:43 UTC |