I get Can't use string ("1") as a HASH ref while "strict refs" in use. You seem to be hiding errors by not using use strict; use warnings;. no autovivification; would also be useful to you.
This kind of mistake elsewhere in your code would definitely explain your symptoms. You're placing all your data in one hash (%1), and you are linking to that hash throughout the tree.
I think your data structure is equivalent to the one below. It would also explain the infinite looping you are experiencing with the recursive solutions.
%{"1"} = ( cat2 => \%{"1"}, cat21 => \%{"1"}, cat22 => \%{"1"}, cat3 => \%{"1"}, ); my %category = ( cat1 => \%{"1"}, );
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: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |