Unique values - improved


But actually we don't need to do it in two steps:


examples/functional/unique_values_shorter.pl
#!/usr/bin/env perl
use strict;
use warnings;

my @data = qw(Earth Mars Earth Venus Earth Mars);
my @unique;
my %seen;

foreach my $value (@data) {
    if (! $seen{$value}++ ) {
        push @unique, $value;
    }
}


print "@unique\n"; # Earth Mars Venus