http://qs321.pair.com?node_id=1066926


in reply to Hash with three keys

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:

use strict; use warnings; sub loop_over_hash { my( $keys, $href ) = @_; print join( ',', @$keys , $href ), "\n" and return unless 'HASH' e +q 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;