On 10/28/07, yitzle <yitzle@xxxxxxxxxxxxxxxxxxxxx> wrote:
> Arrays can be set from lists and arrays get converted to lists all the time.
It's more accurate to say that an array in Perl is always an array
*variable*. Whenever you read the word array, imagine the word
"variable" after it, if that helps. A list in Perl is a list of
scalars; a list is data. An array is the kind of variable which holds
a list; a list is the kind of data which is stored in an array. You
can use the list contained in an array, and you can store a list into
an array. But the array is the container, and the list is the
> Is there any practical difference? (Other than the fact that an array
> has a reference which can be passed as a scalar?)
Yes, there's a practical difference; the same difference as that
between a dozen eggs and the egg carton! Array operators, such as push
and shift, work with an array; you can't push data onto anything but
an array. List operators, such as sort, print, and reverse, work on
lists, not arrays. A Perl subroutine may return a list, it may return
a reference to an array; but it can't possibly return an array.
We didn't always make this distinction clear in the early days of Perl
and Perl documentation. It didn't help that scalar data is stored in
scalar variables. It seemed natural to try to make it happen that
arrays and lists could be considered "the same thing"; but (we realize
now) a list is not an array. So for the past ten years or more, we've
been trying to use the terminology correctly.
Stonehenge Perl Training