Comments posted to date are on target. It might help to conceptually break apart what you're doing when you mash together things like \@ or $$ or @$. Here's your example, using {} to break things up conceptually/visually:

#!/usr/bin/perl use strict; my @array = ('1','2','3','blue','red'); # Get an array reference (via "\@") for the array called "array" my $array_reference = \@{array}; &print_array($array_reference); # print 'blue' # lookup the fourth array element "${X}[3]" of the X defined by $array +_reference print "COLOR: ${$array_reference}[3]\n"; sub print_array { my $reference = shift; # access as an array the thing defined by $reference foreach (@{$reference}) { print "IN THE SUB: $_\n"; } }

The $$x and @$x are shortcuts to ${$x} and @{$x} -- in short, they tell perl how you want the reference to be interpreted -- either as a scalar or an array. The funny one might seem to be $$x[], but just as you access an element of @a with $a[], the array you could get via @{$x} you can access an element of with ${$x}[].

The tutorials suggested above are a good start for more detail

-xdg

Edited to fix display of [].


In reply to Re: References Explanation by xdg
in thread References Explanation 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.