1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| #!perl
# modules and declarations
use strict; use warnings;
sub subtract (&\@\@);
my @tab1 = ("aaa","bbb 123","ccc 456","dd", "mmm pp");
my @tab2 = ("eee","ccc 456"," kkk"," mmm pp","aaa");
# main
for my $nin2 ( subtract {$_} @tab1, @tab2 ) {
print "<$nin2> in \@tab1 and not in \@tab2.\n";
}
for my $nin1 ( subtract {$_} @tab2, @tab1 ) {
print "<$nin1> in \@tab2 and not in \@tab1.\n";
}
# subroutines
sub subtract (&\@\@) {
my ($code, $a, $b) = @_;
my %temp;
@temp{map {$code->()} @$b} = ();
return grep { not exists $temp{$code->()} } @$a;
}
__END__ |
Partager