Subject: | array_diff(@a,@b) works incurrently when there are duplicates in @a |
The implementation of array_diff is build a Set from @b, but not @a. When @a contains identical elements that should be excluded, only one of them is excluded. This behavior can be demonstrated with the following code:
----8<----
use v5.18;
use Array::Utils qw(array_diff);
my (@a, @b);
@a = qw(a b c d);
@b = qw(c d e f);
say join ", ", array_diff(@a, @b); # a, b, e, f
# "a" is duplicated
@a = qw(a a b c d);
say join ", ", array_diff(@a, @b); # a, b, e, f, a
@a = qw(a a a a a a a b c d);
say join ", ", array_diff(@a, @b); # a, a, a, a, a, a, a, b, f, e