in reply to Checking for the existence of a passed parameter.

use CGI qw(param); ... my $verify = param("verify"); if (defined $verify) { # was passed... if ($verify eq "yes") { # was yes... } else { # not yes... } } else { # not passed... }

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re^2: Checking for the existence of a passed parameter.
by Aristotle (Chancellor) on Nov 11, 2003 at 20:02 UTC
    That's somewhat hard to read IMO. It hides the fact that this really is a tristate switch. I'd probably check for not-definedness separately.
    my $verify = param("verify"); if (not defined $verify) { # wasn't even there # ... # return, exit, last, or whatever here } if($verify eq 'yes') { # ... } else { # ... }
    This is Perl, let's not be writing Pascal code. *g*

    Makeshifts last the longest.

      But your code generates warnings when comparing $verify to 'yes' if it's also undef, unless you're absolutely sure that your code doesn't fall out the bottom. I'd write that like this, if you wanna flatten the nesting:
      if (not defined $foo) { ... undef ... } elsif ($foo eq 'yes') { ... yes ... } else { ... everything else ... }

      -- Randal L. Schwartz, Perl hacker
      Be sure to read my standard disclaimer if this is a reply.

        That's why I commented that there should be a "return, exit, last, or whatever" at the end of the first block. Your version is what I should have arrived at, though.

        (I was actually going for a single-if-series solution, but don't know why it didn't occur to me to check the definedness up front. I was irked by having to defined $foo and ... in all conditions before the else-block. Heh. I'm embarrassingly slow lately.)

        Makeshifts last the longest.