The other recursive example goes into an infinite loop.
I presume you mean mine. If so, no it doesn't:
use strict; use warnings; 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); } } my %categories = ( level1 => { 'level1-1' => {}, 'level1-2' => {'level1-2-1' => {}}, 'level1-3' => {}, }, level2 => {'level2-1' => {}}, ); print_tree(\%categories);
level1 ...level1-1 ...level1-2 ......level1-2-1 ...level1-3 level2 ...level2-1
Unless, of course, you don't actually a have tree. Like I said before, %categories doesn't contain what you think it does.
In reply to Re^3: Printing a tree-view of a hash of hashes
by ikegami
in thread Printing a tree-view of a hash of hashes
by pdxperl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |