Daniel Falkenberg wrote:
> Hello All,
>
> I need to print my hash of hashes. For example...
>
> %HoH = (
> flintstones => {
> lead => "fred",
> pal => "barney",
> },
> jetsons => {
> lead => "george",
> wife => "jane",
> "his boy" => "elroy",
> },
> simpsons => {
> lead => "homer",
> wife => "marge",
> kid => "bart",
> },
> );
>
> How can I print that in a readable format. Then I would like to be
> able to print for example...
>
> Simpsons, Lead, homer.
How about a little recursion:
printem(\%HoH);
sub printem {
print join(', ', @_), "\n" and return unless ref($_[-1]) eq 'HASH';
my $h = pop @_;
while (my ($k, $v) = each %$h) { printem(@_, $k, $v) }
}
output:
simpsons, kid, bart
simpsons, lead, homer
simpsons, wife, marge
jetsons, lead, george
jetsons, wife, jane
jetsons, his boy, elroy
flintstones, lead, fred
flintstones, pal, barney
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>