Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: difference between @, $

by TJPride (Pilgrim)
on Dec 07, 2011 at 21:30 UTC ( #942330=note: print w/ replies, xml ) Need Help??


in reply to difference between @, $

@a is an array, or potentially a set of values, while $a is a scalar, or single value. In this case, $a is being used to hold a reference to an array, but the reference is still a single value. I think you probably intended to assign the array values in list context, rather than just adding a reference:

@a = ['1','2','3','4']; ### NO @a = ('1','2','3','4'); ### YES print $_ for @a; ### Prints 1234 print $a[0]; ### Prints 1 ### Note that you use $ and not @ when referring to a ### single item in the array $a = ['1','2','3','4']; print $_ for @$a; ### Prints 1234 print $a->[0]; ### Prints 1 ### The -> is used when it's a reference to an array


Comment on Re: difference between @, $
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://942330]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (14)
As of 2014-07-28 15:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (200 votes), past polls