hello Monks,
maybe I can give my answer ?!? fantastic !! I was warking on dumping HoH on the screen for a better overview and I wrote this:
my %h2=(
'AAA' => 'aaa',
'BBB' => 'bbb',
'CCC' => {'A1' => a1,
'B1' => 'b1',
'C1' => {'A2' => a2,'B2' => 'b2','C2' => 'c2END'}},
'DDD' => 'ddd',
);
my $ref2 = \%h2;
&ddump($ref2);
sub ddump
{
my $ref = shift;
my $deep = shift||1;
foreach my $k (sort keys %{$ref})
{
if (ref( ${$ref}{$k})) {print "\t" x $deep."$k =>\n";
&ddump (${$ref}{$k}, ($deep+1))
}
else {print "\t" x ($deep)."$k => ${$ref}{$k}\n";}
$deep-1;
}
}
Then I found a
column by Merlyn, only 8 year later, that suggested me a new rebus to solve: how about to dump via CGI.pm table ?? or to be precise Hohoh->TableOfTableOfTable here the code:
use warnings;
use CGI qw /:all -nph/; #on Win32
$|++;
$POST_MAX=100;
$DISABLE_UPLOAD=1;
print header();
print start_html();
my %HoHoH = ();#feed your hoh here
my $ref2 = \%HoHoH ;
print &table_center(&complextable($ref2));
print end_html;
sub td_center{{-align=>center} td([@_]); }#separated for customization
sub tr_center {{-align=>center}Tr([@_]); }
sub table_center {
table({-title=>'oOOOo',
-bgcolor=>"#000000",
-border=>1,
-bordercolor=>"red",
-cellspacing=>"0",
-width=>"80%",
-cellpadding=>"0"},
@_);
}
sub complextable
{
my $ref = shift;
my @righe;
foreach my $k (sort keys %{$ref})
{
if (ref( $$ref{$k} ))
{
push @righe,
(&tr_center
(&td_center
($k,(&table_center
(&complextable($$ref{$k}))
)
)
)
) ;
}
else
{
push @righe, (&tr_center(&td_center($k, $$ref{$k} )));
}
}
return @righe;
}
Hope this help. Hope some golf master to squize my homegrown code.
cheers from sunny Roma
Lor*
Originally posted as a Categorized Answer.