You're close, but based on your desired data structure I think what you really want is a hash of a hash of arrays:

k1 => vname1 => [ v1, t1, f1 ] # note: I changed the () to [] vname2 => [ v2, t2, f2 ] k3 => vname3 => [ v3, t3, f3 ]

To create this type of structure, simply assign values like this:

# Assign an array (ref) to the HoH value $hash{$key}{$valname} $hash{$key}{$valname} = [ $value, $type, $flag ]; # option 1 @{ $hash{$key}{$valname} } = ( $value, $type, $flag ); # option 2
Given a $key and $valname, retrieve them like this:
my $type = ${ $hash{$key}{$valname} }[1]; # individual value my @array = @{ $hash{$key}{$valname} }; # all values
I prefer to use the bracket method of dereferencing (rather than the arrow method) because it helps me differentiate between object method calls and dereferences, but it adds keystrokes.

To print all of the data:

foreach my $key ( keys %hash ) { print "$key:\n"; foreach my $valname ( keys %{ $hash{$key} } ) { print " $valname: "; print join( "\t", @{ $hash{$key}{$valname} } ), "\n"; } }
Data::Dumper is very useful here, too:
use Data::Dumper; print Dumper( \%hash );

See the docs (perlref, perldsc) for more info.

HTH


In reply to Re: inner anonymous hash by bobf
in thread inner anonymous hash by anadem

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.