|Perl: the Markov chain saw|
The difference you point out between:
is amusing -- not quite as consistent as I thought.
Now, some questions for you:in List Context there are a number of things which make lists, including:
OK. The list was things that make lists, which are the problematic things Scalar/List context-wise. At that point I was summarising what had been discussed so far... I went on to subroutines and named operators. Sorry if that was less than clear.
what's wrong with the notion of a List in Scalar Context ?Given that an array returns a list in list context, how do you place that list in scalar context?
I would argue that, when treated as an rvalue, this is the key difference between a list and an array. Since in Scalar Context the value of the array isn't the list, the case does not arise.
I understand that it can also be argued that in Scalar Context there are no lists... however much it looks as though there might be.
That the value of @array depends on the Context is one thing to understand. That ($a, $b, $c) or @z[@p] are or are not lists, depending on the Context, seems to me to be harder to get to grips with, and unnecessary.
Finally, an answer to your question:BTW: I'm gagging to know how to describe why this:A list assignment ("() = 1..27") in scalar context ("$r =") evaluates to the number of elements to assign.
Ah. I had expected the second, scalar assignment, to operate on the result of the first assigment. I have now found the place in the book where, by definition, a scalar assignment to the left of a list assignment gets the number of items to the right of the list assignment, not the number of items successfully assigned in that list assignment. (Well, that's clear to me now !)
Thank you. Perl, eh :-)
Finally, and for extra points (and points mean prizes), how does one describe the difference between a list and an array ?An array is variable. A list is a piece of code that generates a list operator.
OK. Well, everybody avoided mentioning the influence of Scalar Context on arrays. But then if lists can only exist in List Context, that wouldn't be worth mentioning :-)