Hi, Thanks for all the replies - most informative!

I've now got working code, something like this:

# Declaration of the data structure my %packet_fields = ( $Idents{ Format_7 } => [qw( ident x y flight_level chksum )], $Idents{ Rotation_Marker } => [qw( ident site_x site_y chksum )], ); # This structure listed for completeness of this example! my %packet_template = ( $Idents{ Rotation_Marker } => "C3 n n n n n n n n n n n n C3", $Idents{ Format_7 } => "C B16 n2 A4 A8 A2 A A A3 C2 +", ); # Referencing the data structure # code here to read $buffer from STDIN # $ident is extracted from $buffer @packet{ @{$packet_fields{ $ident }} } = unpack ( $packet_template{ $ident }, $buffer);
I've got one further question about creating and accessing a hash of hashes.

I'm currently using the following structures:

my %ARP_GLA = ( x => 247866.9, y => 666999.7, ); my %ARP_EDI = ( x => 314382.0, y => 673841.9,
I'd like to combine these into one data structure which I guess is a hash of hashes.

I believe I know enough to create the hash. This should do the trick:

my %ARP = ( GLA => { x => 247866.9, y => 666999.7 }, EDI => { x => 314382.0, y => 673841.9 } );
How do I now access the elements in this structure?

Is it something like:

my $edi_arp = $ARP{EDI}->{x};
Thanks.

R.

--
Robin Bowes | http://robinbowes.com


In reply to Re: Re: Help with hash/array data structure by robinbowes
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.