References are a big spicy meatball! And, of course, there's more than one way to do it.

The following snippet might help:

use strict; my %packet_fields = ( 'Format_X' => ['ident', 'flags', 'x', 'y', 'mode3'], 'Format_Y' => ['ident', 'RDP_Ident', 'Radar_Site_Ident', 'site_x'] ); foreach my $format (keys %packet_fields) { foreach my $field (@{$packet_fields{$format}}) { #line 9 print "$format -> $field\n"; } } foreach my $format (keys %packet_fields) { print "$format's 2nd field = ", $packet_fields{$format}->[1], "\n"; +#line 15 print "$format's 3rd field = ", $packet_fields{$format}[2], "\n"; #l +ine 16 }

In this sample, %packet_fields is a regular old hash. The keys for this hash are garden-variety scalars. The value associated w/ each key is a reference to an anonymous (unnamed) array. These two anon. arrays are the only references that we have to deal with, and the only things that require any dereferencing syntax.

The @{} in line 9 is using a form of dereferencing notation to give me an array.

There's another form of dereferencing that I can use, too, as seen in lines 15 and 16.

Hanlon's Razor - "Never attribute to malice that which can be adequately explained by stupidity"

In reply to Re: Help with hash/array data structure by Art_XIV
in thread Help with hash/array data structure by robinbowes

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.