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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner: Re: [yankee428] @ vs $: Edit Log


Jan 8, 2009, 9:38 AM

Views: 2185
Re: [yankee428] @ vs $

In Reply To
i understand the following

$ is for scalar
@ is for array

what's the difference between


The difference is the first one is in list context and the second one is in scalar context. The first one is also a deprecated form of the second one from earlier versions of perl. The first one can return many values:

@list = @array[1,4,3,2,6];

the second one is a scalar and can return only one value:

$value = $array[0];

Using the proper context is important as it affects the value returned depending on what you are doing or what function you are using to process a list or scalar.

(This post was edited by KevinR on Jan 8, 2009, 9:40 AM)

Edit Log:
Post edited by KevinR (Veteran) on Jan 8, 2009, 9:40 AM

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

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