In this case it's IMHO better to use a hash-slice @hash{LIST}

... it'll give me full control over the order since I can include any LIST not just sorted keys.

But still basically operating on values...

sub base_code { my ($h_codes) = @_; for my $h_planet ( @$h_codes{ sort keys %$h_codes }) { for my $a_aa ( @$h_planet{ sort keys %$h_planet}) { for my $codon ( @$a_aa ) { print $codon, "\n"; } } } }

or for convenience

sub sorted_values { my $h_ref =shift; return @$h_ref{ sort keys %$h_ref } } sub base_code2 { my ($h_codes) = @_; for my $h_planet ( sorted_values $h_codes ) { for my $a_aa ( sorted_values $h_planet ) { for my $codon ( @$a_aa ) { print $codon, "\n"; } } } }

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!


In reply to Re^3: printing complex data structures (hash slice) by LanX
in thread printing complex data structures by ic23oluk

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.