| View previous topic :: View next topic |
| Author |
Message |
brent_weaver Guru


Joined: 01 Jul 2004 Posts: 458 Location: Burlington, VT
|
Posted: Sun Aug 24, 2008 11:01 pm Post subject: Perl - Testing user input for specific values [SOLVED] |
|
|
Hello... I am a newbee @ perl and LOVING IT!!! I need to ask a user a question and give them two choices. If neither is chosen, ask again until one of the valid choices is input. What is the most logical/cleanest way to do this?
Any help is much appreciated! _________________ Brent Weaver
Last edited by brent_weaver on Mon Aug 25, 2008 5:21 pm; edited 1 time in total |
|
| Back to top |
|
 |
Hu Watchman

Joined: 06 Mar 2007 Posts: 6348
|
Posted: Mon Aug 25, 2008 3:48 am Post subject: |
|
|
| Code: | while (<STDIN>) {
chomp;
if ($_ eq "Door number 1") {
print "You win: a potted plant.\n";
last;
}
if ($_ eq "Door number 2") {
print "You win: a gas guzzling pickup truck.\n";
last;
}
print "Sorry, you must choose a door.\n";
}
# At this point, either the user gave up and quit or the user picked one
# of the two doors.
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|