in reply to Check if one array is a subset of another
Use Set::Scalar.
use Set::Scalar; my $bigset = Set::Scalar->new(@bigarray); my $smallset = Set::Scalar->new(@smallarray); my $difference = $bigset - $smallset;
This assumes though that you don't care about array order, and don't care about duplicates - you're treating them as sets.
Preserving order, and assuming you're on Perl 5.10+, you can just use smart match instead...
my $smallarray_ref = \@smallarray; my @difference = grep { !($_ ~~ $smallarray_ref) } @bigarray;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Check if one array is a subset of another
by cstrong (Beadle) on Jan 04, 2012 at 17:18 UTC |