using regex to match your input with the array elements, it's important to use word boundaries (\b) around the variable or a user input of "Ba" will match "Bad" etcmy @answer=( "Bad", "Good", "Not good enough" ); chomp(my $user_answer=<STDIN>); if (grep (/\b$user_answer\b/, @answer)){ print "Ok\n"; }
In reply to Re: Comparison between a string and an array
by edimusrex
in thread Comparison between a string and an array
by Eth443
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |