uniq#

Remove subsequent duplicates by string equality, preserving order.

Registered under both uniq and uniqstr. Both treat elements as strings: two values are the same when their stringifications are byte-for-byte identical. The first occurrence of any given value wins; later duplicates are dropped.

Σύνοψη#

my @subset = uniq    @values;
my @subset = uniqstr @values;
my $count  = uniq    @values;    # scalar context - count only

Τι επιστρέφεται#

In list context, the unique elements in first-seen order. In scalar context, the count of unique elements. undef compares equal to the empty string under uniqstr but is preserved as undef in the output by uniq.

Παραδείγματα#

my @u = uniq    qw( a b a c b );       # ('a', 'b', 'c')
my @u = uniqstr 'a', 'A';              # ('a', 'A') - case matters
my $n = uniq    qw( a b a c b );       # 3

Διαφορές από το upstream#

Fully compatible with upstream.

Δείτε επίσης#

  • uniqnum - compare as numbers rather than as strings.

  • uniqint - compare as integers after truncation.