I admit, I've always thought that 'array' was just Perl's particular jargon for 'list'. Or maybe "Perl's data-structure for holding a list."
If I write
@foo = (1,2,3)
then @foo is an array, while (1,2,3) is a list. Right?
I find myself still confused on the distinction between an array and a list. Could you explain more?
throop | [reply] [d/l] |
It gets more confusing (but then it gets more clear).
@foo is an array
Yes.
while (1,2,3) is a list
1, 2, 3 is a list. The parentheses have nothing to do with its listishness. The parentheses are there only so that the parser doesn't parse the whole expression as:
(@foo = 1), 2, 3;
... as it would if there were no grouping parentheses. They indicate which list you want to assign.
| [reply] [d/l] [select] |
| [reply] |
List and Array have very clear and distinct definitions in Perl.
List is a type of value.
Array is a type of variable.
You can't take the length of a list.
There's no such thing as a reference to a list.
There's no such thing as a list in scalar context.
Come to think of it, that's in the FAQ.
| [reply] |
One more tidbit. The variable @foo is an array, but the expression @foo evaluates to a scalar or a list, depending on context.
my $num_elemens = @foo; # @foo evaluates to a scalar.
my ($first, $second) = @foo; # @foo evaluates to a list.
| [reply] [d/l] [select] |