As was pointed out, it might be better to check using length instead of defined. Remember that zero is false, so a straight logic check will not tell you if it is supplied but zero. Consider:
unless ($query->param('is_a_chicken')) # Fails on 0 { print "You must choose an option.<BR>\n"; }
As your appropriate values might be 0 or 1, this is going to fail on a valid submission. Better to have:
unless (length $query->param('is_a_chicken')) { print "You must choose an option.<BR>\n"; }
Though length does tend to complain about being forced to deal with undefined strings. This will lead to the more verbose but equally more robust version:
my $is_a_chicken = $query->param('is_a_chicken'); unless (defined ($is_a_chicken) && length ($is_a_chicken)) { print "You must choose an option.<BR>\n"; }
Of course, if you were doing this sort of thing all the time you could make a quick helper method to do it quickly:
sub provided { return defined($_[0]) && length ($_[0]); }
Which would simplify as follows:
unless (provided ($query->param('is_a_chicken')) { print "You must choose an option.<BR>\n"; }

In reply to Re^2: check for undefined param name by tadman
in thread check for undefined param name by cameltrader

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.