I've tidied the code up a bit and made the change that you requested. The simplest way to do what you wanted with the table rows is to use map as I've demonstrated below.

#!/usr/bin/perl -w use strict; use CGI qw/ :standard /; my %hash; my $key; my %names; my $value; my $i; foreach $i (1..10) { $key = $i % 3; $value = $i; # The next line is not required due to autovivification # $hash{$key} ||= []; push @{$hash{$key}}, $value; } my @names; foreach $key (0..2) { $names[$key] = "key $key"; print p(join( '/', @{$hash{$key}}), " modulo 3 give $key\n"); } print start_form(); print table(Tr([th(@names), map { td(popup_menu(-name=>'0', -values=>[@{$hash{$_}}], -default=>$hash{$_})) } keys %hash +])); print end_form(); print end_html();
--
<http://www.dave.org.uk>

"Perl makes the fun jobs fun
and the boring jobs bearable" - me


In reply to Re: hashes in CGI.pm by davorg
in thread hashes in CGI.pm by rbi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.