basic perl array question

T

Tarscher

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
 
I

it_says_BALLS_on_your forehead

Tarscher said:
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.
 
I

it_says_BALLS_on_your forehead

Tarscher said:
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
 
P

Paul Lalli

Tarscher said:
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
 
T

Tad McClellan

it_says_BALLS_on_your forehead said:
Tarscher wrote:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top