I have two arrays of strings with repeated values that I would like to compare and get the number of add/del/upd(=same) elements:
my @array1 = ("aaa", "bbb", "ccc", "eee", "eee");
my @array2 = ("aaa", "aaa", "bbb", "ccc", "ccc", "ddd", "fff");
I need something like:
add: 4
del: 2
upd: 3
I tried 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);
But it cannot work for repeated values:
$VAR1 = 'intersection (upd): 3';
$VAR1 = 'only first (del): 1';
$VAR1 = 'only second (add): 2';
How can I solve this problem?
This will do what you need.
I trust the mechanism is clear. If you need further explanation please ask again.
output