* Ingo Blechschmidt ([EMAIL PROTECTED]) [050519 16:52]:
> Should it be possible to give an own comparator block, similar as with
> grep? E.g.
>   uniq <a b a a c d>;   # <a b a c d>
> 
>   uniq:{ abs $^a == abs $^b } 42, 23, -23, 23, 42
>                         # 42, 23, 42

'uniq' differs from 'sort' because there is no order relationship between
the elements.  A quick algorithm for finding the unique elements in perl5
is
   sub uniq(@)
   {  my %h = map { ($_ => 1) } @elements;
      keys %h;
   }
or
   sub uniq(@)
   {  my %h;
      $h{$_}++ for @elements;
      keys %h;
   }

anyway: O(n), which is much better than sort can do.

For your proposal, the requested code only requires this
    uniq:{ abs $^a } 42, 23, -23, 23, 42, 42, 23, 42

    uniq:{lc} @words
-- 
               MarkOv

------------------------------------------------------------------------
drs Mark A.C.J. Overmeer                                MARKOV Solutions
       [EMAIL PROTECTED]                          [EMAIL PROTECTED]
http://Mark.Overmeer.net                   http://solutions.overmeer.net

Reply via email to