Not a recommendation by any means, but just another way to do it. It's essentially a recursive approach unrolled which is done by maintaining your own stack and probably quite handy when you're optimizing recursive algorithms (see. Unrolling recursion for more info).my %hash = ( foo => { bar => { baz => 'one', quux => 'two', }, }, field => 'value', this => { that => undef, }, ); my @stack = \%hash; my @path; while(@stack) { my($k,$v); unless( ($k, $v) = each %{ $stack[0] } ) { shift @stack; pop @path; next; } if(ref $v eq 'HASH') { unshift @stack => $v; push @path => $k; } else { print join('/' => @path, $k), " => ", ( defined $v ? $v : "undef" ), "\n"; } } __output__ foo/bar/quux => two foo/bar/baz => one this/that => undef field => value
_________
broquaint
In reply to Re: Printing Hashes (Without Data Dumper)
by broquaint
in thread Printing Hashes (Without Data Dumper)
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |