Google Groups Home
Help | Sign in
FAQ 4.39 What is the difference between a list and an array?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
PerlFAQ Server  
View profile
 More options May 17, 3:03 am
Newsgroups: comp.lang.perl.misc
From: PerlFAQ Server <br...@stonehenge.com>
Date: Sat, 17 May 2008 00:03:02 -0700
Local: Sat, May 17 2008 3:03 am
Subject: FAQ 4.39 What is the difference between a list and an array?
This is an excerpt from the latest version perlfaq4.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .

--------------------------------------------------------------------

4.39: What is the difference between a list and an array?

    An array has a changeable length. A list does not. An array is something
    you can push or pop, while a list is a set of values. Some people make
    the distinction that a list is a value while an array is a variable.
    Subroutines are passed and return lists, you put things into list
    context, you initialize arrays with lists, and you "foreach()" across a
    list. "@" variables are arrays, anonymous arrays are arrays, arrays in
    scalar context behave like the number of elements in them, subroutines
    access their arguments through the array @_, and "push"/"pop"/"shift"
    only work on arrays.

    As a side note, there's no such thing as a list in scalar context. When
    you say

            $scalar = (2, 5, 7, 9);

    you're using the comma operator in scalar context, so it uses the scalar
    comma operator. There never was a list there at all! This causes the
    last value to be returned: 9.

--------------------------------------------------------------------

The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.

If you'd like to help maintain the perlfaq, see the details in
perlfaq.pod.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google