In a scalar context, a list evaluates to the number of elements it contains.
More precisely, in a scalar context a list assignment returns the number of items on the right-hand side.
If anyone ever says of Perl "a list in a scalar context", then you know they've fallen victim to a very common misconception. They'll usually end that with "returns the last item in the list", but that wouldn't have made sense in this case.
The fact is that there is no one rule for what you get when you "put a list in a scalar context". Some would even say that you can't put a list into a scalar context. I prefer to say that it depends on what the "list" is. Because I don't feel that "list" is a well-defined term in Perl.
There are a great many "things that would return a list if used in a list context" and each of them can have their own rule for what they return if used in a scalar context. The most common is "last item", though exactly what an "item" is can be a bit tricky to define. (:
- tyeIn reply to Re^2: undef var ("list in scalar context")
by tye
in thread undef var
by aapada
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |