In this chapter, we'll use the terms list and
array as the Perl language thinks of them.
Take ("alpha", "beta",
"gamma"); that's a list of
the names of the first three Greek letters, in order. To store that
list into a variable, use an array, as in
@greeks =
("alpha", "beta",
"gamma"). Both are ordered groups of scalar
values; the difference is that an array is a named variable, one
whose array length can be directly changed, whereas a list is a more
ephemeral notion. You might think of an array as a variable and a
list as the values it contains.
This distinction may seem arbitrary, but operations that modify the
length of these groupings (like push and
pop) require a proper array and not merely a list.
Think of the difference between $a and
4. You can say $a++ but not
4++. Likewise, you can say
pop(@a) but not pop
(1,2,3).
The most important thing to glean from this is that Perl's lists and
arrays are both ordered groupings of scalars. Operators and functions
that work on lists or arrays are designed to provide faster or more
convenient access to the elements than manual access would provide.
Since few actually deal with modifying the array's length, you can
usually use arrays and lists interchangeably.
Let's have some more terminology. The scalar items in an array or
list are called elements, which you access by
specifying their position, or index. Indices
in Perl start at 0. So, given this list: