You can find all the info you need at perlref and perllol. Here's a brief description, though.

When you have a reference to something, there are two ways you can dereference it. By dereference I mean "take the pointer to an object and return the object." You can prefix the reference with the data type indicator or use the dereference operator. For example:

my @array = ('cow', 'dog', 'cat'); my $ref_to_array = \@array; my ($first, $second) = @{$ref_to_array}[0,1]; # prefix my $third = $ref_to_array->[2]; # deref operator

This really comes in handy when you have four levels deep of referencing and you need something at the bottom. Typically, the deref operator (->) is optional between multiple levels of dereferencing. For example:

my @LoL = (); # empty array $LoL[0] = []; # ref to anonymous array $LoL[0]->[0] = []; # another ref to anonymous array # the hard way ${${$LoL[0]}[0]}[0] = 'Look, up in the sky!'; # the easy way $LoL[0]->[0]->[1] = 'It's a bird, it's a plane, it's...'; # the shortcut $LoL[0]->[0][2] = 'Superman!';

Now that you have more information than you needed or wanted... In this particular example, Perl "Does What You Mean." When you write $LoL[5][3] Perl recognizes that there's no way to rewrite that to mean anything but what you meant to do in the first place. =) So it just assumes the shortcut.

That's probably the worst example of anything I've ever given. Go read the perldocs! {g}


In reply to Re: Re: Re: Array of arrays by mwp
in thread Array of arrays by cajun

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.