in reply to Printing a tree-view of a hash of hashes
as I see every third level element in the hash being printed, not just the third level elements associated with the current second level.
That's not possible from the code you printed. It would suggest that %categories doesn't contain what you think it does.
Note that there can be different levels of hierarchy
Sounds like you need a recursive solution.
sub print_tree { my ($tree, $depth) = @_; $depth ||= 0; my $indent = '...' x $depth; for (sort keys %$tree) { print($indent, /^\s*\z/ ? "<blank>" : $_, "\n"); print_tree($tree->{$_}, $depth+1); } } print_tree(\%categories);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Printing a tree-view of a hash of hashes
by Tux (Canon) on Jun 01, 2010 at 11:14 UTC |