Hi,
I'm trying to learn the use of hashes with CGI.pm. Here is a short code where I create an array of hashes (think so.. :) ), and then I use it in a form created with CGI.pm.
#!/usr/bin/perl -w use CGI qw/ :html3 /; my %hash; my $key; my %names; my $value; my $i; foreach $i (1..10) { $key = $i % 3; $value = $i; $hash{$key} ||= []; push @{$hash{$key}}, $value; } $query = new CGI; print $query->header(); foreach $key (0..2) { $names[$key] = "key $key"; print $query->p(join( '/', @{$hash{$key}}), " modulo 3 give $key +\n"); } print $query->start_form(); # print $query->table( TR([ th(@names), td(print $query->popup_menu ( -name=>'0', -values=>[@{$hash{0}}], -default=>$hash{0}) ), td(print $query->popup_menu ( -name=>'1', -values=>[@{$hash{1}}], -default=>$hash{1}) ), td(print $query->popup_menu ( -name=>'2', -values=>[@{$hash{2}}], -default=>$hash{2}) ), # # Instead, I'd like to write a single instruction # I know this can't work ... it's just a note # # td($query->popup_menu ( -name=>"$key", # -values=>[@{$hash{$key}}], # -default=>$hash{$key}) # ), ]) ); print $query->end_form(); print $query->end_html();
How can I generate those popup menus in a single instruction (or in any case without explicitly pointing at the keys of the hashes)?
thanks in advance.
Roberto

In reply to 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.