CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Frequently Asked Questions:
What is the difference between $array[1] and @arra

 



Jasmine
Administrator

Jan 19, 2001, 3:03 PM

Post #1 of 1 (1534 views)
What is the difference between $array[1] and @arra Can't Post

(From the Perl FAQ)

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

The former is a scalar value, the latter an array slice, which makes 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:

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

with

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

The -w flag will warn you about these matters.


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives