DEV Community

Discussion on: De-duplicate arrays in Python, Perl and Ruby

Collapse
 
jgpuckering profile image
Gary Puckering • Edited

As of perl 5.20 you can use a hash slice:

my @dups=(1,2,1,2,1,2);
my @nodups = do { my %h; @h{ @dups } = (1) x @dups; keys %h };

Add a sort before keys if you need them ordered.