in reply to Removing Duplicates in an array?

I found this about a month ago, but not sure where. I think it was in a POD, but not really sure though. You have to first make sure the array is sorted...
@array = sort { $a cmp $b } @array; # Now remove dups. %saw = (); @de_duped_array = grep (!$saw{$_}++, @array);
That works for me.

Good luck.

Replies are listed 'Best First'.
Re: Re: Removing Duplicates in an array?
by davorg (Chancellor) on Jun 26, 2001 at 17:57 UTC
      Thanks davorg, you're right. I was thinking of a previous version I had tried of that statement that didn't use a hash in the way it is using here.
Re: Re: Removing Duplicates in an array?
by the_0ne (Pilgrim) on Jun 26, 2001 at 17:39 UTC
    Ok, just went to my home node and I noticed that I had a link to the 'How can I extract just the unique elements of an array?' That IS where I found the example. Sorry bout the clutter.