in reply to Re^2: Printing a tree-view of a hash of hashes
in thread Printing a tree-view of a hash of hashes
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Printing a tree-view of a hash of hashes
by pdxperl (Sexton) on Jun 01, 2010 at 15:06 UTC | |
by ikegami (Patriarch) on Jun 01, 2010 at 15:39 UTC |