For checkboxes, you could use a hash, since each checkbox has a different value:

my %field1 = map { $_ => $_; } @{$r->param('field1')}; my %field2 = map { $_ => $_; } @{$r->param('field2')}; my %field3 = map { $_ => $_; } @{$r->param('field3')};

You can check the hashes directrly ($field1{'red'}) or you can then line them up in an array:

my @array_pos = qw( black blue red ); my @field1 = @field1{@array_pos}; my @field2 = @field2{@array_pos}; my @field3 = @field3{@array_pos};

This also handles browsers which return the params in random order, which I'm pretty sure is legal.

Test code:

my $r = { field1 => [qw( black blue red )], field2 => [qw( black red )], field3 => [qw( blue )], }; ... change $r->param(...) to $r->{...} ... my $row_num = 0; printf(" %-6s %-6s %-6s\n", @array_pos); printf(" %-6s %-6s %-6s\n", ('-'x6)x3); foreach my $row (\@field1, \@field2, \@field3) { printf("%d: ", $row_num++); foreach my $col (0..2) { printf("%-6s ", $row->[$col]); } print("\n"); } black blue red ------ ------ ------ 0: black blue red 1: black red 2: blue


In reply to Re: Multiple rows in web forms by ikegami
in thread Multiple rows in web forms by Mutant

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.