in reply to macthing a word a in array of words
Take a look at perlop for the list of operators. You need to use eq and ne for string comparison instead == and !=. Also, grep is a good function to be familiar when dealing with arrays.
use strict; my @words = qw(foo bar baz biz); for (1..2) { print "enter a word:"; chomp(my $word = <STDIN>); if (grep {$word eq $_} @words) { print "found MATCH!!"; last; } }
|
|---|