irvson has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: while loop almost correct
by Perlbotics (Archbishop) on Nov 15, 2009 at 01:06 UTC | |
|
Re: while loop almost correct
by toolic (Bishop) on Nov 15, 2009 at 01:31 UTC | |
by irvson (Sexton) on Nov 17, 2009 at 23:24 UTC | |
|
Re: while loop almost correct
by JadeNB (Chaplain) on Nov 15, 2009 at 07:25 UTC | |
by irvson (Sexton) on Nov 17, 2009 at 23:26 UTC | |
|
Re: while loop almost correct
by biohisham (Priest) on Nov 15, 2009 at 13:52 UTC | |
by JadeNB (Chaplain) on Nov 17, 2009 at 20:38 UTC | |
by irvson (Sexton) on Nov 17, 2009 at 23:28 UTC | |
by irvson (Sexton) on Nov 18, 2009 at 16:25 UTC | |
|
Re: while loop almost correct
by Anonymous Monk on Nov 17, 2009 at 10:15 UTC | |
by irvson (Sexton) on Nov 17, 2009 at 23:32 UTC |