You are probably going to have to loop through the list, looking in it for
the data input:
my $input = 'undef';
my @possible_list = ('one', 'two','three');
until ($input eq "exit")
{
print "\nPlease type one of @possible_list ";
chomp ($input = <STDIN>);
foreach my $entry( @possible_list )
{
if ("$input" eq "list") {
# do stuff
}
else{ # don't do stuff }
}
}
Advanced: To avoid looping, use a hash instead of an array:
"Gary Merrick" <[EMAIL PROTECTED]> wrote in message
00b401c2cce3$201ba3c0$6401a8c0@BLIVOT">news:00b401c2cce3$201ba3c0$6401a8c0@BLIVOT...
> I'm taking a beginning Perl class, and we haven't gotten to pattern
matching
> yet. I need to somehow test for user input being numeric. I think. <:-)
>
> The second "elsif" is where I'm hung up. It seems to catch any kind of
invalid
> input, text or numeric. Also, without the first "elsif" statement, users
typing
> "exit" will be given an "Invalid input" error before exiting. (sigh)
Could
> somebody please point me in the right direction? Any help would be very
much
> appreciated.
>
> Here's what I have so far:
>
>
> my $input = 'undef';
> until ($input eq "exit") {
> print "\nPlease type one of [list, imdb_number, exit]: ";
> chomp ($input = <STDIN>);
> if ("$input" eq "list") {
> # do stuff
> }
> elsif ("$input" eq "exit") {
> # Do nothing.
> # Without this part, user gets "Invalid input" message before exiting.
> }
> # This part seems to catch any kind of invalid input, and it never gets
> # to "else". Why? I guess I need to test for numeric input (if it's not,
> # it goes to "else"), and then see if the number matches one of these:
> elsif ("$input" == "0120611"||"0106308"||"0088247"||"0267804"||"0094074"||
> "0102798"||"0120382"||"0196229"||"0272152"||"0109830") {
> # do stuff
> }
> else {
> print "\n\tInvalid input. Please try again.\n";
> }
> }
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]