Baz has asked for the wisdom of the Perl Monks concerning the following question:

How might I fill my table field with values for a hash. That is, lets say I have values stoed in a hash as follows, how can I enter them into my table -
my %number = ( 'One' => '1', 'Two' => '2', 'Three' => '3', ); print $h->table({-bgcolor=>"#99FF00"}, $h->Tr({-align=>'center', -valign=>'top'}, $h->td({-width=>"34%", -height=>"14", -class=>"e", -align=>"center"} +,1), $h->td({-width=>"33%", -class=>"d", -align=>"center"},1), $h->td({-width=>"33%", -class=>"d", -align=>"center"},1), ), $h->Tr({-align=>'center', -valign=>'top'}, $h->td({-width=>"34%", -height=>"14", -class=>"e", -align=>"center"} +,2), $h->td({-width=>"33%", -class=>"d", -align=>"center"},2), $h->td({-width=>"33%", -class=>"d", -align=>"center"},2), ), );
1 1 1
2 2 2
I'd also like to use a for look, to iterate through the hash. I'm not sure how many values I'll have in my hash when printing the table.

Replies are listed 'Best First'.
Re: Filling cgi.pm table with hash values
by cLive ;-) (Prior) on Mar 23, 2004 at 19:41 UTC
    print map { $h->Tr({-align=>'center', -valign=>'top'}, $h->td({-width=>"34%", -height=>"14", -class=>"e", -alig +n=>"center"},$number{$_}), $h->td({-width=>"33%", -class=>"d", -align=>"center"},$n +umber{$_}), $h->td({-width=>"33%", -class=>"d", -align=>"center"},$n +umber{$_}), ) } keys %number;
    but they won't come out in the order you expect (unless you sort by value, which makes the hash pretty irrelevant in this instance :)

    cLive ;-)

      Cool, thanks for your help.