⭐ in reply to How to find and remove duplicate elements from an array?
In fact, the code for sub unique is a one liner; you could just hork and use it verbatim:use strict; use Array::Utils qw(:all); my @array = qw( a b c d c d e f g g g g g f); my @unique_array = unique(@array); print "@unique_array\n"; __END__ prints: e c a g b d f
There's also the (arguably more standard) List::MoreUtils::uniq.@unique_array = keys %{{map { $_ => undef } @array }};
Its code is nearly a one-liner. Copying it would look like this:
my %seen; @unique_array = grep { not $seen{$_}++ } @array;
|
|---|