On 2/27/09 Fri Feb 27, 2009 2:05 PM, "Gunnar Hjalmarsson" <nore...@gunnar.cc> scribbled:
> Which takes us to the obvious step of validating the user input. > > my $normal; > while (1) { > print 'Do you want to do the normal thing? [yes] : '; > chomp( $normal = <STDIN> ); > $normal = 'yes' if $normal eq ''; > last if grep { lc $normal eq $_ } 'yes', 'no'; We lazy people don't like typing more than one character, and I like to accept 't' for true and 'f' for false as well, so I usually use: last if $normal =~ /^[yntf]/i; > print "\nERROR: Answer must be yes or no.\n\n"; > } -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/