tsk1979 has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks,
consider an array @a and an array @b. I want to find out wether all the elements of @a are there in @b
for example
@a = (-true, -depth=1)
@b = (-search, -depth=1, -true, -expand_all...)
In the above case the command should return true, all the elements in @a are in @b. I implemeted this foreach
use strict;
use warnings;
use Array::Compare;
my @ar1 = qw(-true -depth=1);
my @ar2 = qw(-search -depth=1 -true -expand_all);
my $comp = Array::Compare->new();
if ($comp->compare(\@ar1, \@ar2)){print "Same Array OK";}else{print "
+Different Array OK";}
use List::MoreUtils qw(all);
use strict;
use warnings;
my @partial = qw(-true -depth=1);
my @complete = qw (-search -depth=1 -true -expand_all);
my %temp;
@temp{@complete} = @complete;
print "Yep\n" if all { exists $temp{$_} } @partial;
O. K., I'm not too serious about proposing this. Though it meets my sense of elegance (somehow).
Also note that no counting takes place: If an element appears more than once in @a they will be covered by a single (identical) entry in @b for acknowledging their containment.