Remove duplicate value from an array in perl

Remove duplicate value from an array in perl

 

#!/usr/bin/perl -w
use strict;
use warnings;
sub unique {
    my %seen;
    grep !$seen{$_}++, @_;
}

my @array = qw(one two three two three);
my @filtered = unique(@array);

print @filtered . "\n";

Output:-

one two three

Leave a Reply