Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > basic perl array question

Reply
Thread Tools

basic perl array question

 
 
Tarscher
Guest
Posts: n/a
 
      03-22-2006
Hi all,

I have been looking for this on the net but I didn't found an answer.
Maybee you guys can help me out?

I m using GD to create charts and have to use the $graph->plot(\@data)
command somewhere. The \@ interests me and I don't know why I can just
use $ or @ ?

Thanks in advance
Stijn

 
Reply With Quote
 
 
 
 
it_says_BALLS_on_your forehead
Guest
Posts: n/a
 
      03-22-2006

Tarscher wrote:
> Hi all,
>
> I have been looking for this on the net but I didn't found an answer.
> Maybee you guys can help me out?
>
> I m using GD to create charts and have to use the $graph->plot(\@data)
> command somewhere. The \@ interests me and I don't know why I can just
> use $ or @ ?
>


This is not really a Perl array question, but you didn't know that so I
can't fault you for that. The backslash means that it's a reference. So
instead of passing the @data array, you are passing a reference to
@data.

 
Reply With Quote
 
 
 
 
it_says_BALLS_on_your forehead
Guest
Posts: n/a
 
      03-22-2006

Tarscher wrote:
> Hi all,
>
> I have been looking for this on the net but I didn't found an answer.
> Maybee you guys can help me out?
>
> I m using GD to create charts and have to use the $graph->plot(\@data)
> command somewhere. The \@ interests me and I don't know why I can just
> use $ or @ ?


A more complete explanation of references can be found using the
following command:
perldoc perlref

 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      03-22-2006
Tarscher wrote:
> I have been looking for this on the net but I didn't found an answer.
> Maybee you guys can help me out?
>
> I m using GD to create charts and have to use the $graph->plot(\@data)
> command somewhere. The \@ interests me and I don't know why I can just
> use $ or @ ?


Because they are vastly different things.

@data is an array named 'data'
$data is a scalar variable named 'data'

Other than their names, @data and $data have NOTHING to do with one
another. Not even a little bit.

\@data is a reference to the array named @data. It is a single scalar
value. It references the array @data.

To answer your question about why you have to pass a reference to @data
rather than @data itself, the simple answer is "That's how the module
designer created it.". *Why* he/she created it that way is an answer I
cannot give without digging into the module. A likely possibility is
that the method in question wants/needs to directly modify the array
that it wants passed in. While possible to do without references,
this is much cleaner to do with references.

For more information on references, please read:
perldoc perlreftut
perldoc perllol
perldoc perldsc
perldoc perlref

For more information on subroutines and their arguments, please read:
perldoc perlsub

Paul Lalli

 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      03-22-2006
it_says_BALLS_on_your forehead <(E-Mail Removed)> wrote:
> Tarscher wrote:



>> The \@ interests me


> A more complete explanation of references can be found using the
> following command:
> perldoc perlref



And a less complete, but much easier to digest, explanation of
references can be found using the following command:

perldoc perlreftut


--
Tad McClellan SGML consulting
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
TurboTax Basic vs. Taxcut Basic? Sharp Dressed Man Computer Support 1 01-12-2009 12:52 PM
What is the difference between Visual Basic.NET and Visual Basic 6? Jimmy Dean Computer Support 3 07-25-2005 07:05 AM
Re: Python interpreter in Basic or a Python-2-Basic translator. rrr@ronadam.com Python 0 05-02-2005 01:48 PM
Python interpreter in Basic or a Python-2-Basic translator. Engineer Python 6 05-01-2005 10:16 PM
Upgrading Microsoft Visual Basic 6.0 to Microsoft Visual Basic .NET Jaime MCSD 2 09-20-2003 05:16 AM



Advertisments