perldoc CGI states:

If a value is not given in the query string, as in the queries "name1=&name2=" or "name1&name2", it will be returned as an empty string. This feature is new in 2.63.

So, assuming you're using version 2.63 or later, and assuming that the parameter is being passed in the query string, only with no value (as in 'search_string=&blah_blah_blah=bar'), you'll want this instead of what you're using:

if ($var ne '')

On a side note, as I was testing the above statement of CGI.pm, I found that if the parameter is the only thing in the query string, and has no value, then param() returns undef instead of the expected '' empty string. Anyone know of a reason for this? Is it a bug, or is it expected behavior? I tested with CGI 2.752

echo "foo" | perl -MCGI=param,-debug -le'defined param("foo") and prin +t "defined!"' # doesn't print defined! ?? echo "foo=" | perl -MCGI=param,-debug -le'defined param("foo") and pri +nt "defined!"' echo "foo&" | perl -MCGI=param,-debug -le'defined param("foo") and pri +nt "defined!"' echo "&foo" | perl -MCGI=param,-debug -le'defined param("foo") and pri +nt "defined!"' # these all print defined!

HTH

--
3dan

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.