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


Joined: 01 Jul 2004 Posts: 388 Location: Burlington, VT
|
Posted: Sun Aug 24, 2008 6: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
GE Healthcare IT
Burlington, VT
Last edited by brent_weaver on Mon Aug 25, 2008 12:21 pm; edited 1 time in total |
|
| Back to top |
|
 |
Hu Veteran

Joined: 06 Mar 2007 Posts: 2595
|
Posted: Sun Aug 24, 2008 10:48 pm 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
|
|