Click here to get back home

FAQ 4.40 What is the difference between $array[1] and @array[1]?

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
FAQ 4.40 What is the difference between $array[1] and @array[1]? PerlFAQ Server 02-27-2008
Get Chitika Premium
Posted by PerlFAQ Server on February 27, 2008, 9:03 pm
Please log in for more thread options
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.40: What is the difference between $array[1] and @array[1]?

The former is a scalar value; the latter an array slice, making it a
list with one (scalar) value. You should use $ when you want a scalar
value (most of the time) and @ when you want a list with one scalar
value in it (very, very rarely; nearly never, in fact).

Sometimes it doesn't make a difference, but sometimes it does. For
example, compare:

$good[0] = `some program that outputs several lines`;

with

@bad[0] = `same program that outputs several lines`;

The "use warnings" pragma and the -w flag will warn you about these
matters.



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

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.

Similar ThreadsPosted
Beginner: read in lines array1 and after keyword array2 July 30, 2006, 7:37 am
What is the difference between if( -f $f ) and unless( -d $f )? October 25, 2004, 8:07 pm
difference between $ and @ March 14, 2008, 3:08 am
FAQ 8.46: What's the difference between require and use? December 18, 2004, 12:03 pm
Difference between redirects January 22, 2005, 1:16 pm
FAQ 8.46 What's the difference between require and use? March 23, 2005, 12:03 pm
difference between two files April 1, 2005, 2:43 pm
FAQ 8.46 What's the difference between require and use? June 5, 2005, 11:03 am
FAQ 8.46 What's the difference between require and use? September 29, 2005, 4:03 am
FAQ 8.46 What's the difference between require and use? January 30, 2006, 12:03 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap