Your second take is much better, much more indented, but try and keep things neat. Your closing brace in your foreach, for example, is strangely at the end of a line which is also sans-semicolon.

Anyway, to "derefence" something is to take a reference and use it to obtain a value. References are what make people exposed to C for the first time look all green and dizzy, but they're really not that bad, especially in Perl.

Here's a really, really brief introduction to references:
my @array = qw[ 1 2 3 ]; my $array_ref = \@array; # Backslash makes a reference my @array_copy = @$array_ref; # @ de-references array reference $array[2] = 4; # Modifies @array directly print $array_ref->[2]; # Should be '4' now $array_ref->[1] = 5; # Modifies @array by reference print $array[1]; # Should be '5' $array_copy[1] = 6; # Modifies @array_copy, not @array print $array[1]; # Still '5'
For a much more detailed document, check out perlref.

Fortunately, or unfortunately depending on your opinion, Perl will automagically dereference for you in certain circumstances. Where $foo->{bar} is actually an "ARRAY" reference, you should really sub-address that as $foo->{bar}->[1] and not $foo->{bar}[1], but either should work.

In reply to Re^3: Associative Array Trouble by tadman
in thread Associative Array Trouble by EmmittSmith

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.