sub uniq {
my %seen;
grep !$seen{$_}++, @_;
}
my @array = qw(one two three two three);
my @filtered = uniq(@array);
print "@filtered\n";
Outputs:
one two three
If you want to use a module, try the uniq
function from List::MoreUtils
What's the simplest way to print a Java array?
How do I write a correct micro-benchmark in Java?
What is a raw type and why shouldn't we use it?
How can I fix 'android.os.NetworkOnMainThreadException'?
What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it?
What is a NullPointerException, and how do I fix it?
How do I compare strings in Java?