I want to check if an array of single words (strings) contains several specific words, in any order.
I have this code, cobbled together from advice found online:
my %hash = @allwords; #puts array in hash to search / compare. if (exists $hash{'word1' && 'word2' && 'word3'}) { ...do stuff ; }
I want the if to be true if all the words are found, in any order. But it's returning true
if just word3 is found. I think it's ignoring word1 and word2.
I'm too new at Perl to know if it's even appropriate syntax, although it doesn't give any error currently.
I've also found a technique using $_ eq, but it doesn't seem to be matching the way I want:
Keep in mind, I never found any solution to match several values; so this && tactic is a semi-educated guess.if ( grep { $_ eq 'word1' && 'word2' } @allwords ) { ...do stuff; }
p.s. I don't know why the code format is so tiny in the preview.. I can hardly read the code. But hopefully
it's not that way when I post it.
In reply to Check array for several matches by Bman70
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |