uniqnum#
Remove subsequent duplicates by numerical equality, preserving order.
Synopsis#
my @subset = uniqnum @values;
my $count = uniqnum @values; # scalar context — count only
What you get back#
In list context, the unique numerical values in first-seen order.
In scalar context, the count. undef is treated as 0 and
coerced to 0 in the output (matching upstream’s numerical
handling). +0.0 and -0.0 are treated as equal. Every NaN is
treated as a duplicate of every other NaN, despite NaN != NaN.
Examples#
my @u = uniqnum 1, 1.0, '1', 2; # (1, 2)
my @u = uniqnum 0, -0.0; # (0)
my $n = uniqnum 1, 2, 3, 2, 1; # 3
Differences from upstream#
Fully compatible with upstream.
See also#
uniq— string-equality deduplication.uniqint— integer-equality deduplication (ignores fractions).