ecuguru has asked for the wisdom of the Perl Monks concerning the following question:

After using a custom parser for handling gets/posts to my perl scripts, I moved over to use CGI qw/:standard/;. Very happy with it. But I had a bug sneak up on me, that I can't enter a 0 as a value anymore. I have other scripts that will provide me &val=0 for a zero, but my cgi code is treating it like null.
my $first = param( 'first' ) || 'notentered';
if I pass it &first=0 it will use notentered.

Can provide test site if neccesary to reproduce. Would sure like to be able to accept zeros again. Running on mac 10.3.9, perl 5.8.1
thanks!

Replies are listed 'Best First'.
Re: CGI.pm accepting a 0 as a value, not null
by PodMaster (Abbot) on Oct 11, 2005 at 06:27 UTC
    my $first = param('first'); $first = 'notentered' unless defined $first;

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

      got it, one lined
      my $first = (defined param('first'))? param('first'):'notentered';
      I used to have Defined in my old code! dunno wtf i didn't think of using it also.
      thanks!
Re: CGI.pm accepting a 0 as a value, not null
by japhy (Canon) on Oct 11, 2005 at 12:51 UTC
    If your version of Perl is recent enough, you can do: my $first = param('first') // 'notentered';

    Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
    How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart