Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Hash to HTML display

by grummerX (Pilgrim)
on Jul 18, 2002 at 10:30 UTC ( [id://182748]=note: print w/replies, xml ) Need Help??


in reply to Hash to HTML display

Merlyn has already posted a better solution, but in the interest of TMTOWTDI here's one using Data::Dumper:
#!c:/perl/bin/perl -w use strict; use Data::Dumper; my $our_hash = { 'Cows' => { 'Brown' => undef, 'Green' => undef, 'Strawberry' => { 'Spotted' => undef, 'Solid' => undef }, 'Orange' => undef }, 'Dogs' => { 'Purple' => { 'Spotted' => undef, 'Solid' => undef } } }; $Data::Dumper::Quotekeys = 0; for (Dumper $our_hash){ s/\$VAR1 = //; s/{/<UL>/g; s/}/<\/UL>/g; s/(undef)?[,;]?\n/\n/g; s/\n *([^\n]*)=>/\n<LI>$1<\/LI>/g; print; }
Not really pretty or robust, but it works with a simple hash like your sample ... you'd need to flesh it out a little if you wanted it to be able to handle quotes, etc. Like I said, Merlyn's solution is better, but I couldn't resist giving this a try...

Update: Added closing </LI> tag per flocto's encouragement.

-- grummerX

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://182748]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (6)
As of 2024-04-23 10:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found