note
hdb
<p>
Recursion is another solution to this, especially if you do not know upfront how deep your hashes are nested or if the depth is not the same everywhere:
</p>
<code>
use strict;
use warnings;
sub loop_over_hash {
my( $keys, $href ) = @_;
print join( ',', @$keys , $href ), "\n" and return unless 'HASH' eq ref $href;
loop_over_hash( [ @$keys, $_ ], $href->{$_} ) for keys %$href;
}
my %hash = (
a => {
1 => { x => 5, y => 6 },
2 => { s => 7, t => 8 }
},
b => {
3 => 'end',
},
);
loop_over_hash [], \%hash;
</code>
1066916
1066916