in reply to Re^4: Skipping parameters in sprintf %, elegantly
in thread Skipping parameters in sprintf %, elegantly
One way to think of it is that a list is a series of things (scalars) separated by commas while an array is a single variable that contains a list.
You appear to be conflating two of the most common things that Perl people tend to mean when they say "list": a "list literal" and a "list of scalar values". In a list literal, things are separated by commas but those things don't need to be scalars. An array contains a list of scalar values (but these aren't separated by commas inside of the array, of course).
A list in a scalar context evaluates to whatever the last item in the list would be in a scalar context
That is true of a "list literal" and not lots of other types of lists.
Despite the rampant ubiquity of "what is the difference between array vs. list in Perl" questions and musings, the question itself should mostly just be rejected. Once you pick your definition for "list" to not be a hodge-podge of concepts from quite different categories ("list literal" is a construct of Perl syntax while "list of scalar values" is an abstract concept while "list of SVs on perl's stack" doesn't fall into either of those categories). While an array is a Perl variable type and there is no "list" Perl variable type.
So "list vs. array" is like "what is the difference between a structure and an object method". The responses that should come to mind are "what do you mean by 'structure'?" (that is, "what do you mean by 'list'?") and "you are comparing apple software vs. orangutans".
And the most common declaration that comes out of 'list vs. array' is "a list in scalar context returns it's last item" for which a common response is "there is no such thing as a list in a scalar context". That last "list" is talking about a "list of scalar values" or, more specifically "a list of SVs on a perl stack". But that is also incorrect. It is almost true while also being an important Perl concept. For most cases, there being a scalar context means that no list of SVs will be generated and pushed onto the stack. But there are several cases where the list of SVs is generated and the scalar context just means that all but one of them gets thrown away.
Now, an important and more general concept in Perl that can be called "list", is "list expression" (of which "list literal" is a subset). But "list expression" is a bit misleading in Perl given that previous note that most such don't actually involve a "list" (of scalar values) when evaluated in a scalar context. So a more precise name would be "expression that would produce a list of scalar values if evaluated in a list context". So you can see why this important concept gets called just "list" which leads to confusion especially when mixed with people who have adopted a definition of "Perl list" equal to either "list literal" or "list of SVs on a stack".
Then there are things like the "list" of characters that go between square brackets in a regular expression's character class, to name just one...
- tye
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Skipping parameters in sprintf %, elegantly ("list")
by kyle (Abbot) on Aug 25, 2008 at 02:39 UTC |