in reply to Re: Lexical variables question
in thread Testing for filled-in box with CGI::param() ?

$var will be defined, but false. Try if ($var) instead.

Why do you think that $var can't be "undef"? If param returns "undef" then $var will be undefined.

--
<http://www.dave.org.uk>

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

Replies are listed 'Best First'.
Re3: Lexical variables question
by dragonchild (Archbishop) on Aug 12, 2003 at 15:25 UTC
    Because it won't be undef from a checkbox. That was the real question from the OP. It will be undef if the name is wrong. It will be defined if the name is there and is a checkbox. It will be ''.

    ------
    We are the carpenters and bricklayers of the Information Age.

    The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

      Because it won't be undef from a checkbox.

      Who said anything about a checkbox? In fact, who said anything about CGI? All we know for sure is that there is some function called param and it takes a string as a parameter.

      If I was going to make the huge assumption that we're talking about the param function from CGI.pm then my first guess would be that a control called "search_string" would be a textbox not a checkbox.

      And besides, a CGI program should never make assumptions about the form that calls it. The query might come from a faked up form that has completely different controls on it. Or it might be a query that was built from scratch by a Perl script using LWP and have half of the required parameters missing.

      You're making an awful lot of assumptions here.

      --
      <http://www.dave.org.uk>

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

        Anytime I see a function called that's named param() in a question on PM and there's no other info, CGI is a pretty good assumption. This is even stronger given that it's Anonymonk asking the question.

        You're right - 'search_string' is most likely a textbox, not a checkbox. However, the same argument still holds.

        You're also right in that definedness should be checked for safety. However, truth, not definedness, should be checked for functionality. My reading of the OP's question was that it was a concern of functionality, not safety, of a CGI form s/he was having problems with. You're welcome to disagree, but the question isn't being answered without a few assumptions.

        ------
        We are the carpenters and bricklayers of the Information Age.

        The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

        Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.