in reply to Re: Eliminate duplicate and original values
in thread Eliminate duplicate and original values

More compactly as,
$hash{$_}++ foreach (@array); @array2 = grep( ($hash{$_} == 1), keys %hash );

Replies are listed 'Best First'.
Re: Re: Re: Eliminate duplicate and original values
by jryan (Vicar) on Nov 26, 2001 at 00:38 UTC
    I came up with this, at 46 chars:
    @array=do{grep$_{$_}<2,grep{!$_{$_}++}@array};
    Of course, if we were truely golfing, that comes out at:
    sub find_duplicates { #23456789_123456789_123456789_ grep$_{$_}<2,grep{!$_{$_}++}@_ }
    30 characters :)
      Eliminating the hashes chops it down to 24, but of course it won't run with strict refs in use.
      #23456789_123456789_1234 grep$$_<2,grep{!$$_++}@_

      -Matt

Re: Re: Re: Eliminate duplicate and original values
by jlongino (Parson) on Nov 26, 2001 at 00:16 UTC
      This does not eliminate the duplicate elements. See the requirements in the root node.
      If the original array contains A1, B2, C3, C3, D4, then the output should contain A1, B2, D4.
      C3 should not be included.
      That's a very clever way of obtaining unique values though and will get copied in other places, if you don't mind. :)