Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Unique values - improved

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

#!/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