To the extent that your sample data structure reflects the structure of your actual data structure, what you have here is not actually an HoAoA...oA as such, because at various levels you have a heterogenous array of both arrays and strings (and the strings happen to look an awful lot like numbers). That's... *weird*. It's possible to traverse it, but at every step you'll have to check whether the next element is an array reference, a string, or what...

sub flatten { # Depth-first traversal. my @scalar; foreach my $item (@_) { if (ref $item eq 'ARRAY') { push @scalar, flatten(@$item); } elsif (ref $item eq 'HASH') { push @scalar, $_, flatten($$item{$_}) for keys %$item; } elsif (ref $item) { push @scalar, ref $item; } else { push @scalar, $item; } } return @scalar; } print join ', ', flatten $VAR2; print "\n";

But perhaps the more important question is, why is your data structure like this in the first place? All I've done is traverse your structure and extract all the non-structure bits, but if the structure has meaning, I'm not seeing it from the sample data. Yet, presumably there was some reason for all that structure. Maybe we could see it ourselves if you posted (a few of) the actual data. Or maybe not, but it might be worth a try. Perhaps if you describe for us what the structure means, we could understand better what you want to do with it.


Sanity? Oh, yeah, I've got all kinds of sanity. In fact, I've developed whole new kinds of sanity. You can just call me "Mister Sanity". Why, I've got so much sanity it's driving me crazy.

In reply to Re: Accessing the Array values in a multilevel hash by jonadab
in thread Accessing the Array values in a multilevel hash by Anonymous Monk

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.