in reply to Re: printing complex data structures (values)
in thread printing complex data structures

Using values allows more direct access to nested hash values, but pay heed to haukex's update note here discussing the fact that keys allows control of the ordering of access to hash values, and this may be very important, in particular for large data structures. (See also perldsc.)


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^3: printing complex data structures (hash slice)
by LanX (Saint) on Jul 24, 2017 at 16:50 UTC
    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!