Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: Hash of Arrays of Hashes Parsing

by gryphon (Abbot)
on Sep 17, 2003 at 20:24 UTC ( #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.

code('Perl') || die;

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2020-12-06 02:02 GMT
Find Nodes?
    Voting Booth?
    How often do you use taint mode?

    Results (65 votes). Check out past polls.