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
--In reply to Re: Lexical variables question
by edan
in thread Testing for filled-in box with CGI::param() ?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |