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

How do you specify an empty value when using the param method from the CGI module? I am trying to write a conditional of the form: if ($query->param($key)== "" ){........} but this seems to always evaluate to true whether the key has a value or not. Thanks for the help.
  • Comment on Beginner needs help with very simple issue

Replies are listed 'Best First'.
Re: Beginner needs help with very simple issue
by btrott (Parson) on Feb 16, 2000 at 04:19 UTC
    I'm not sure exactly what you're asking for--first off, you're using the wrong comparison operator. You should be using "eq", because you're testing string equality:
    if ($query->param($key) eq "") {....}
    But are you asking how to tell if the paramater has been set or not? If so, use defined:
    if (defined $query->param($key)) {....}