Arrays and Lists -perl

On 10/28/07, yitzle <yitzle@users.sourceforge.net> 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 ofscalars; a list is data. An array is the kind of variable which holdsa list; a list is the kind of data which is stored in an array. Youcan use the list contained in an array, and you can store a list intoan array. But the array is the container, and the list is thecontents.
> 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 thatbetween a dozen eggs and the egg carton! Array operators, such as pushand shift, work with an array; you can't push data onto anything butan array. List operators, such as sort, print, and reverse, work onlists, not arrays. A Perl subroutine may return a list, it may returna 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 Perland Perl documentation. It didn't help that scalar data is stored inscalar variables. It seemed natural to try to make it happen thatarrays and lists could be considered "the same thing"; but (we realizenow) a list is not an array. So for the past ten years or more, we'vebeen trying to use the terminology correctly.
Cheers!
--Tom PhoenixStonehenge Perl Training
This entry was posted in 未分类. Bookmark the permalink.

One Response to Arrays and Lists -perl

  1. 李昌勇 says:

    老大,写简单点看不懂啊:em210:

发表评论

您的电子邮箱不会被公开。 标记为 * 的区域必须填写

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>