perlaintdead:

There are multiple approaches you could take, but to choose one, you'd have to know how you want to access your data. If you have a varying list of keys, for example, you could make a subroutine that would unravel the hashes:

my @keys = qw( kittehs weather tailflic ); my $value = unravel_hash(\%meows, @keys ); sub unravel_keys { my $ref = shift; while (@_) { my $key = shift; return undef if ! exists $ref->{$key}; $ref = $ref->{$key}; } # Ran out of keys, so $ref is the requested value return $ref; }

Of course, if you have array references mixed in, you'll have to make more complex code to check whether to reference by hash key or array index.

However, the module Data::Diver already does this for you, so you could just download and install it!

...roboticus

When your only tool is a hammer, all problems look like your thumb.


In reply to Re: hashes in the Nth dimension by roboticus
in thread hashes in the Nth dimension by perlaintdead

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.