#!/usr/bin/perl
use List::Compare;
my @arr1 = qw( free bsd shmsd );
my @arr2 = qw( shmsd yo );
my $lc = List::Compare->new( \@arr1, \@arr2 );
# intersection
my @intersection = $lc->get_intersection;
print "@intersection\n";
# union
my @union = $lc->get_union;
print "@union\n";
# outersection
my @outersection = $lc->get_symmetric_difference;
print "@outersection\n";
############
#!/usr/bin/perl
use Data::Dumper;
use List::MoreUtils qw( none );
@arr1 = qw( free bsd shmsd );
@arr2 = qw( shmsd );
# shrink @arr 1 by @arr2
@arr1 = grep {
my $arr1 = $_;
none { $_ eq $arr1 } @arr2
} @arr1;
print Dumper( \@arr1 );
( prints [free bsd] )
############
#!/usr/bin/perl
use Data::Dumper;
use List::MoreUtils qw( any );
@arr1 = qw( free bsd shmsd );
@arr2 = qw( shmsd );
# find common between @arr1 and @arr2
@arr1 = grep {
my $arr1 = $_;
any { $_ eq $arr1 } @arr2
} @arr1;
print Dumper( \@arr1 );
( prints [shmsd] )
No comments:
Post a Comment