Gentoo Forums
Gentoo Forums
Quick Search: in
Perl - Testing user input for specific values [SOLVED]
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
brent_weaver
Guru
Guru


Joined: 01 Jul 2004
Posts: 458
Location: Burlington, VT

PostPosted: Sun Aug 24, 2008 11:01 pm    Post subject: Perl - Testing user input for specific values [SOLVED] Reply with quote

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
View user's profile Send private message
Hu
Watchman
Watchman


Joined: 06 Mar 2007
Posts: 6348

PostPosted: Mon Aug 25, 2008 3:48 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
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