my @a=("a","b","c","d","e");
my @b=("b","g","f","e");my %a=map{$_=>1} @a;
my %b=map{$_=>1} @b;# 交集
@A = grep( $a{$_}, @b ) ;# 补集
@B1=grep(!defined $a{$_}, @b);
@B2=grep(!defined $b{$_}, @a);# 并集
%C=map {$_=>1} @a,@b;
@C=keys %C;
Perl 数组 交集,补集,并集
时间: 2024-10-05 00:03:53