Spenser has asked for the wisdom of the Perl Monks concerning the following question:
I have this bit of opening code for a CGI script--actually, I have it in many scripts.
#!/usr/bin/perl -w use strict; use CGI qw/:standard/; my $q = new CGI; my $choice = param('choice') || 1;
This works just fine until recently when I tried to pass a parameter value of 0 (i.e., script.cgi?choice=0). If I give it zero within quotes (i.e., script.cgi?choice='0'), it works. Otherwise, the value reverts to the default of 1.
It seems to be thinking that 0 is nothing. Is there any way that I can tell it to accept 0 through the web browser and to only use the || value when results are null? Or do I have to reverse my script after this parameter and make the default 0? Another possibility would be to put the value in quotes when sending it from the previous script. I guess that would be easy enough. I'm just wondering if there's a notation to param() that I could use instead.
-Spenser
That's Spenser, with an "s" like the detective.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: param = 0, not NULL
by davorg (Chancellor) on Mar 29, 2007 at 13:13 UTC | |
|
Re: param = 0, not NULL
by shigetsu (Hermit) on Mar 29, 2007 at 13:09 UTC | |
|
Re: param = 0, not NULL
by f00li5h (Chaplain) on Mar 29, 2007 at 13:07 UTC | |
by leocharre (Priest) on Mar 29, 2007 at 13:22 UTC | |
by davorg (Chancellor) on Mar 29, 2007 at 13:26 UTC | |
|
Re: param = 0, not NULL
by Ojosh!ro (Beadle) on Mar 29, 2007 at 15:41 UTC | |
|
Re: param = 0, not NULL
by Moron (Curate) on Mar 29, 2007 at 15:23 UTC | |
|
Re: param = 0, not NULL
by Burak (Chaplain) on Mar 30, 2007 at 10:33 UTC |