First the code:

print "Question #1: Who is buried in Grant's tomb?\n\n"; print "A. Grant\n"; print "B. Yoda\n"; print "C. Liberace\n"; print "D. None of the above.\n\n\n\n"; print "The answer is: "; chomp($reply = <STDIN>); #Following loop to test for a-d answers, courtesy of PerlMonks.org. #This works but will not accept any answer without going thru this #code block once print "\nPick a letter between a and d.\n"; chomp(my $reply = <STDIN>); while ($reply !~ /^[a-d]$/i) { print "\nPick a letter between a and d -- or else!\n"; chomp($reply = <STDIN>); }

If you've read the comments, you know what I can't fix. The code that I got here at Perlmonks does the job, but no response to the question will be accepted until that "while" loop runs once. When I asked for help a couple of weeks ago, I didn't include the code that showed the question. Maybe that would have made a difference. So, the question now is: How can I make sure that the answer to the question shown in the code is in the range a-d without showing the warning "Pick a letter between a and d" when the answer falls in the proper range?


In reply to while loop almost correct by irvson

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.