Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: A Simple Question From A Simple Man

by kcott (Chancellor)
on Oct 10, 2012 at 23:19 UTC ( #998341=note: print w/replies, xml ) Need Help??

in reply to A Simple Question From A Simple Man

G'day TinkerTantrum,

Welcome to the monastery.

In your code, $rocks and @rocks are two entirely different variables. Variables with a $ are scalar values; those with an @ are arrays.

When you use brackets ([]) in the manner shown in your code, you are creating a reference to an array (typically just called an arrayref) - that's what ARRAY(0x1434d80) is referring to. You can also get a reference to an array by putting a backslash in front of the array name (e.g. \@array_name).

You can access elements of an array with this syntax: $array_name[index] (where index is an integer). You can access elements of an arrayref with this syntax: $array_ref->[index] (again, index is an integer).

Here's an extension to the code you posted showing all of these:

$ perl -le ' use warnings; $rocks = [1..23]; @rocks = qw/hail slate poop drop/; print $rocks; print $rocks->[0]; print \@rocks; print $rocks[0]; ' ARRAY(0x7fe363803ae8) 1 ARRAY(0x7fe36382b108) hail

Have a read through these documentation pages for a more in-depth description: perlintro, perldata and perlref.

You should also declare your variables. my is the most frequently used way of doing this - perlsub has a lot more information about this and other ways to declare variables.

In addition to use warnings;, you should also add use strict; to the start of your code: this is one of the first things you'll read about in perlintro; details can be found in strict.

Finally, if you just want to "get some interaction going with my fellow Monks", you can use the Chatterbox (typically referred to as the CB) which should be on the panel to your right.

-- Ken

Replies are listed 'Best First'.
Re^2: A Simple Question From A Simple Man
by TinkerTantrum (Novice) on Oct 10, 2012 at 23:55 UTC

    Aha! It all makes sense now. Thank you for the insight Mr. kcott. I must return to the dojo and meditate on this. You have been a true help!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://998341]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2017-06-24 09:38 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (557 votes). Check out past polls.