quoting Damian's original mail[1]:
>  uniq      - remove duplicates without reordering
                                ^^^^^^^^^^^^^^^^^^

Would not that mean the original order of the first ocurrence is
preserved? This is what Ruby Array#uniq does:

[4,1,2,4,2,3,5].uniq  => [ 4, 1, 2, 3, 5]

The behavior is consistent with the description given "ri Array#uniq"

------------------------------------------------------------- Array#uniq
     array.uniq   -> an_array
------------------------------------------------------------------------
     Returns a new array by removing duplicate values in _self_.

        a = [ "a", "a", "b", "b", "c" ]
        a.uniq   #=> ["a", "b", "c"]

A naïve Perl 5 implementation could be:

sub uniq {
  my (@u, %h);
  for (@_) {
    push(@u, $_) unless $h{$_};
    $h{$_}++;
  }
  return @u;
}

Adriano.

Reply via email to