You should use an array or a hash instead of separate variables. What happens when you add $four, $five, and $five_hundred_fifty_five? I have no idea how you are setting $one, $two, and $three, but i'll bet it's not pretty.

You don't have to use CGI.pm, but here is an example script that does. The usage for CGI.pm's checkbox_group() method is quite daunting - i still have to refer to the docs (and sprinkly a little chicken blood) when using it. The key is to create a hash whose keys are the values of the checkbox, and whose values are the labels of the checkbox (i wish that were the other way around, btw). For example:

my %label = ( one => 'foo', two => 'bar', three => 'baz', );
From here, it's just a matter of faith to create a checkbox_group:
print checkbox_group( -name => 'checkbox', -values => [keys %label], -labels => \%label, );
But now that that complexity is over, look how easy it is to create another hash whose keys are one, two, and three, and whose values are either yes or no:
# create an array whose keys all have values 'no' my %checkbox = map { $_ => 'no' } keys %label; # update each found key's value to 'yes' $checkbox{$_} = 'yes' for param('checkbox');
Here is a complete script that you can tinker with:
#!/usr/bin/perl -T use strict; use warnings; use CGI qw(:standard); my %label = ( one => 'foo', two => 'bar', three => 'baz', ); print header, start_html('checkbox test'), start_form, checkbox_group( -name => 'checkbox', -values => [keys %label], -labels => \%label, ), submit('go'), end_form, ; if (param('go')) { my %checkbox = map { $_ => 'no' } keys %label; $checkbox{$_} = 'yes' for param('checkbox'); print table({border=>1}, Tr(th[qw(Var Val)]), map Tr(td[$_,$checkbox{$_}]), keys %checkbox ); }
Hope this helps. :)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to (jeffa) Re: Changing each item in an array by jeffa
in thread Changing each item in an array by Anonymous Monk

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.