http://qs321.pair.com?node_id=292246


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;