in reply to •Re: Hash to HTML display
in thread Hash to HTML display
Maybe I'm a little too picky here, but I want to encourage everybody to write "right" HTML; with XHTML in mind, of course.. I edited merlyn's code so it creates XHTML conform output:
sub hash_to_html ($;$) { my $x = shift; my $i = @_ ? shift : ''; return "" unless ref ($x) eq "HASH"; return "$i<ul>\n" . join ('', map { "$i <li>$_</li>\n" . hash_to_html ($x->{$_}, "$ +i ") } sort (keys (%$x))) . "$i</ul>\n"; }
Which prints (with the input above):
<ul> <li>Cows</li> <ul> <li>Brown</li> <li>Green</li> <li>Orange</li> <li>Strawberry</li> <ul> <li>Solid</li> <li>Spotted</li> </ul> </ul> <li>Dogs</li> <ul> <li>Purple</li> <ul> <li>Solid</li> <li>Spotted</li> </ul> </ul> </ul>
Regards,
-octo
|
---|
Replies are listed 'Best First'. | |
---|---|
•Re: Re: Hash to (X)HTML display
by merlyn (Sage) on Jul 18, 2002 at 14:57 UTC | |
by flocto (Pilgrim) on Jul 18, 2002 at 15:18 UTC | |
•Re: Re: Hash to (X)HTML display
by merlyn (Sage) on Jul 18, 2002 at 17:46 UTC |