in reply to Comparison between a string and an array
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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Comparison between a string and an array
by Eth443 (Initiate) on May 04, 2015 at 21:09 UTC | |
by edimusrex (Monk) on May 05, 2015 at 14:26 UTC | |
by AnomalousMonk (Archbishop) on May 05, 2015 at 17:24 UTC | |
by edimusrex (Monk) on May 05, 2015 at 19:50 UTC |