Can anybody tell me how to push a duplicate element of an array to a new array?
This is what I have till now, again I want to retain the duplicate elements into a new array.
%seen = ();
@uniq = ();
foreach $item (@list) {
unless ($seen{$item}) {
$seen{$item} = 1;
push(@uniq, $item);
}
}
print "@unique\n";
If you’re trying to find values that appear more than once:
If you’re trying to put the values that are only found once in
@uniqand values that are found twice or more in@dups:If you’re trying to put the first instance of a value in
@uniqand the second and subsequent values in@dups: