That first Regexp will fart. See, the way it's written, it will match either a 'y' at the beginning of the string, a 'yes' or 'n' anywhere in the string, or a 'no' at the end. You need to put parens around the patterns to isolate them from the anchors. Also, I'd prefer an elsif to nested ifs:

if (/^(y|yes)$/i) { print "YIPPEEE.!!!!\n"; } elsif (/^(n|no)$/i) { print "Begone, evil peon!\n" } else { # Validate user input and return message if invalid print "\n\n=====================================\n"; print "You Have Entered and Incorrect Option\n"; print "Valid Options are [Y/N]\n"; print "=====================================\n\n"; &answer; }

However, I would much prefer to use a for as a switch case:

SWITCH: for ($input) { /^(y|yes)$/i && do { print "YIPPEEE.!!!!\n"; last SWITCH; }; /^(n|no)$/i && do { print "Begone, evil peon!\n"; last SWITCH; }; # Validate user input and return message if invalid print "\n\n=====================================\n"; print "You Have Entered an Incorrect Option\n"; print "Valid Options are [Y/N]\n"; print "=====================================\n\n"; &answer; }

LAI
:eof

In reply to Re^2: Yes No Validation by LAI
in thread Yes No Validation by J9

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.