The stupid question is the question not asked | |
PerlMonks |
Current Perl documentation can be found at perldoc.perl.org.
Here is our local, out-dated (pre-5.6) version:
There are several possible ways, depending on whether the array is ordered and whether you wish to preserve the ordering.
$prev = 'nonesuch'; @out = grep($_ ne $prev && ($prev = $_), @in);
This is nice in that it doesn't use much extra memory, simulating
uniq(1)'s
behavior of
removing only adjacent duplicates. It's less nice in that it won't work
with false values like undef, 0, or ``''; ``0 but true'' is ok, though.
undef %saw; @out = grep(!$saw{$_}++, @in);
@out = grep(!$saw[$_]++, @in);
undef %saw; @saw{@in} = (); @out = sort keys %saw; # remove sort if undesired
undef @ary; @ary[@in] = @in; @out = @ary;