A really good book to get is O'Reilly's Advanced Perl Programming if you are going to get into this sort of thing. But here is my brief explanation.

Let's say you have an array reference...

my $r_array = [ 'inky', 'blinky', 'blu' ];
Now the question is, what exactly is in $r_array? It's sort of similar to the concept of pointers in C: a reference contains the address of where the data is actually located in memory. If you print $r_array directly, you get something funky looking like ARRAY(0xc70858), which is clearly not the data stored in the array. So think about your reference this way: it's just a sign saying where the data really is.

To get at the data where it really is, you have to dereference the reference, using the following syntax:

@{ $r_array }
You could use it in code, like this:
for ( @{ $r_array } ) { print "$_\n"; }
Now, as a shorthand, Perl lets you omit the curly braces (for reference variables only):
for ( @$r_array )


In reply to Re: How do I access an array for which I only have a reference? by little_mistress
in thread How do I access an array for which I only have a reference? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.