level1 ...level1-1 ...level1-2 ......level1-2-1 ...level1-3 level2 and so on..I need to print the tree in sorted order at each level. I don't want to use Data::Dumper, because it's used by someone non-technical who just wants to check the hierarchy of some data they entered. Note that there can be different levels of hierarchy, there aren't necessarily three levels for each entry. I know I'm doing something wrong with printing the third level, as I see every third level element in the hash being printed, not just the third level elements associated with the current second level. When I check with Data::Dumper, the hash is correct, so there's something wrong with how I'm accessing the third level. The code below doesn't work
print Dumper(\%categories); foreach $top ( sort keys %categories){ if($top =~ /^\s*$/){$top="<blank>";} print "$top\n"; foreach $second ( sort keys %{$categories{$top}}){ if($second =~ /^\s*$/){$second="<blank>";} print "...$second\n"; foreach $third (sort keys %{$categories{$top}{$second}}){ if($third =~ /^\s*$/){$third="<blank>";} print "......$third\n"; } } }
In reply to Printing a tree-view of a hash of hashes by pdxperl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |