in reply to Changing each item in an array
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:
From here, it's just a matter of faith to create a checkbox_group:my %label = ( one => 'foo', two => 'bar', three => 'baz', );
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:print checkbox_group( -name => 'checkbox', -values => [keys %label], -labels => \%label, );
Here is a complete script that you can tinker with:# 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');
#!/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 ); }
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)
|
|---|