Your specification is rather sparse. However a big heads up in your code is that you are using nested loops. That just ain't going to work. Every time you add a level to your hash you will need to add another nested loop and you really don't want to go there.
The common technique is to write a recursive sub to do the work. Consider:
use strict; use warnings; use 5.010; my %categories = ( level1 => { 'level1-1' => {}, 'level1-2' => {'level1-2-1' => {}}, 'level1-3' => {}, }, level2 => {'level2-1' => {}}, ); dumpHash(\%categories); sub dumpHash { my ($subHash, $indent) = @_; $indent //= ''; given (ref $subHash) { when ('') {print "$indent$subHash\n" if defined $subHash} when ('HASH') { for my $key (sort keys %$subHash) { print "$indent$key\n"; dumpHash($subHash->{$key}, "$indent "); } } } }
Prints:
level1 level1-1 level1-2 level1-2-1 level1-3 level2 level2-1
In reply to Re: Printing a tree-view of a hash of hashes
by GrandFather
in thread Printing a tree-view of a hash of hashes
by pdxperl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |