Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Hash of Arrays of Hashes Parsing

by gryphon (Abbot)
on Sep 17, 2003 at 20:24 UTC ( [id://292246]=note: print w/replies, xml ) Need Help??


in reply to Hash of Arrays of Hashes Parsing

Greetings SmokeyB,

I was bored (and I think I'm coming down with a fever, so coding is always fun) so I coded up some stuff for you. It's not good code, but it may help you get in the direction you're looking for. I made the assumption that "into tables" means "into HTML tables".

#!/usr/bin/perl use strict; use warnings; my %foo = ( Info => [ { MakeEng => 1, MakeFre => 2, ModelEng => 3, ModelFre => 4, ModelYear => 5, }, { MakeEng => 6, MakeFre => 7, ModelEng => 8, ModelFre => 9, ModelYear => 0, }, ], VIN => { VINStatus => 'active', VechileDT => 'on', }, ); foreach my $table (keys %foo) { print '<h3>', $table, '</h3>', "\n"; print "<table>\n"; if (ref $foo{$table} eq 'HASH') { print '<tr><td>', $_, '</td><td>', $foo{$table}{$_}, "</td></tr>\n +" foreach (keys %{$foo{$table}}); } elsif (ref $foo{$table} eq 'ARRAY') { print '<tr>'; print '<td>', $_, '</td>' foreach (keys %{$foo{$table}[0]}); print "<tr>\n"; foreach my $row (@{$foo{$table}}) { print '<tr>'; print '<td>', $_, '</td>' foreach (values %{$row}); print "<tr>\n"; } } else { print "<tr><td>Badness. Something unexpected in %foo</td></tr>\n"; } print "</table>\n\n"; } exit;

I don't know the extent of your project, but if you're looking for something long-term that's going to map into some kind of web reporting thing, you should definately take a look at HTML::Template. Using that, you could just muck around a little with your %foo and then just pass that into a template. Magic then happens.

gryphon
code('Perl') || die;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-25 14:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found