我有两个具有重复值的字符串数组,我想比较它们并获取 add/del/upd(=same) 元素的数量:
my @array1 = ("aaa", "bbb", "ccc", "eee", "eee");
my @array2 = ("aaa", "aaa", "bbb", "ccc", "ccc", "ddd", "fff");
我需要类似的东西:
add: 4
del: 2
upd: 3
我试过List::Compare:
my @array1 = ("aaa", "bbb", "ccc", "eee", "eee");
my @array2 = ("aaa", "aaa", "bbb", "ccc", "ccc", "ddd", "fff");
my $lc = List::Compare->new(\@array1, \@array2);
print Dumper "intersection (upd): ".scalar($lc->get_intersection);
print Dumper "only first (del): ".scalar($lc->get_unique);
print Dumper "only second (add): ".scalar($lc->get_complement);
但它不适用于重复值:
$VAR1 = 'intersection (upd): 3';
$VAR1 = 'only first (del): 1';
$VAR1 = 'only second (add): 2';
我怎么解决这个问题?