You are looking for something to check if one list is a subset of another one. List::Compare has functions that do that. You pass two lists to the constructor then you can call a method to find if the list on the right is a subset of the one on the left or vice versa. Take note that you use the backslash to pass a reference of the array. If you try to pass two lists to a function they get mixed up.
use warnings; use strict; use List::Compare; my @allwords = qw( mary had a little lamb its fleece was white as snow + ); my @checkwords1 = qw( little lamb fleece everywhere ); my @checkwords2 = qw( little lamb fleece ); my $lc1 = List::Compare->new(\@allwords, \@checkwords1); my $lc2 = List::Compare->new(\@allwords, \@checkwords2); ## See if the list on the Right, @checkwords, ## is a subset of the list on the left, @allwords. print "Check 1: All words were ", $lc1->is_RsubsetL ? "" : "not ", "fo +und.\n"; print "Check 2: All words were ", $lc2->is_RsubsetL ? "" : "not ", "fo +und.\n"; __END__ Check 1: All words were not found. Check 2: All words were found.
In reply to Re: Check array for several matches
by Lotus1
in thread Check array for several matches
by Bman70
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |