in reply to Hash to HTML display
The array @path needs to keep a record of all the keys it went through to get to level it is on the tree. Below I got this kind of working. The array @path needs to be poped again if the sub is on the last item in a group. I can't explain this very well at all so you might want to try the sub out yourself (with the above hash) :)
{ my @path; sub hash_gen { my $cats = shift; unless (ref $cats eq 'HASH') { pop @path; return undef; } my ($output, $level) = ('', 0); foreach my $cat (sort {uc($a) cmp uc($b)} keys % $cats) { push @path, $cat; $output .= '<li>' . join(' -> ', @path) . "</li>\n"; pop @path; $output .= hash_gen($cats->{$cat}) . "\n"; } return "<ul>$output</ul>"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Hash to HTML display
by Anonymous Monk on Jul 18, 2002 at 10:27 UTC |