in reply to param = 0, not NULL

use CGI qw/:standard/; my $q = new CGI; my $choice = param('choice') || 1;

This has nothing to do with your question but you seem slightly confused by the function-based and OO interfaces to CGI.pm. You're creating a CGI object, but then ignoring it to use the function-based interface. You don't need that my $q = new CGI;.

As for your problem, your code is just doing what you are telling it to do. Your code is saying "set $choice to the parameter 'choice', unless that parameter has a false value, in which case set $choice to be 1". 0 has a false value, so if you send a parameter of 0 then you'll end up with 1.

You need to understand the difference between a value being "defined" and a value being "true". Here, you are interested in whether the parameter is defined, not whether it is true.

In the forthcoming Perl 5.10, there is a new "defined-or" operator that does exactly what you want. So you'll be able to write:

my $choice = param('choice') // 1;

But that's not out yet, so you'll have to do something like this:

my $choice = param('choice'); $choice = 1 unless defined $choice;
--

See the Copyright notice on my home node.

"The first rule of Perl club is you do not talk about Perl club." -- Chip Salzenberg