I'm new to Perl. (I prefer "neophyte" to "newbie.") I'll post the code, then tell you what I'm trying to do.
do { print "\nPick a letter between a and d.\n "; chomp($reply = <STDIN>); } while (lc $reply ne ('a' .. 'd'));
I want the user to answer multiple choice questions by choosing the letters "a" thru "d." If any other letter is entered, I want the script to show the first "print" line. Once a letter "a" thru "d" is entered, I want the script to continue to the question. I tried "while" and "if" loops (without "do"), and I ended up with a loop that just kept repeating "Pick a letter between a and d." Using "do" -- as shown -- has, at least, created the situation where the "Pick a letter..." sentence appears once, and then the script waits for another input. BUT...even when I enter a letter "a" thru "," the script keeps repeating "Pick a letter..." I've gotten the impression that the range operator works only with arrays, which is not the case here.
So, I have two questions: 1) How do I specify that the input must be in the range "a thru d?" 2) How do I get the script to move on to the question once an accepted letter has been entered.
Thanks.
In reply to do-while loop by irvson
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |