I have the zeal of the convert about CGI.pm, and I think you were 100% right to offer this as the solution. The various difficulties that
chriso got tangled in, and which the other posters help unpick, would have been avoided altogether by using CGI.pm... that's one of the great things about it, that other, far cleverer people than I, have thought about all the problems I'm going to encounter and provided ready-to-wear solutions, so I can get on with being creative.
(Plus it's easier to read / debug by somebody else, it's quicker to type out, it's easier to cut 'n' paste into another script without disaster, you get no-brainer error-proof parameter parsing, you don't have to think about headers, you get support for CGI::Carp
etc etc... in other words
use CGI or die;)
Speaking as someone who used to write his CGIs out longhand on the principle that "by the time I've learnt to use CGI.pm I could have written the script from scratch" I can report with hindsight that this attitude is b*ll*cks.
I mention this in the hope of encouraging anyone who hasn't done so yet to make the jump.
My only reservation abt your solution is that you import the standard methods, but then create a CGI object - which I
think means effectively importing them twice, and certainly involves extra keystrokes :). It works just the same without any OO at all:
#!/usr/bin/perl -w
use CGI qw/ :standard /;
use strict;
my @checkbox_items = qw/one two three four five/;
print header,
start_html( -title => 'Checkbox group sample using CGI.pm' ),
start_form;
print checkbox_group(
-name => 'testing',
-values => \@checkbox_items,
-linebreak => 1,
), submit, end_form;
my @checkbox_values = param( 'testing' );
print p( 'Check a button or two and click Submit Query to see the chec
+ked values.' ),
li,
join '<LI>', @checkbox_values;
print end_html;
§
George Sherston