[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl-AnyPerl] an elegant uniquing



On Mon, 7 Feb 2000 11:01:01 -0500, Chris Nandor wrote:

>The other suggestions are good, but mine is eviler, and eviler is gooder.
>
>  @unique = grep { ! $seen{ $_->{names} }++ and $_ = $_->{names}, 1 } @loh;

Which modifies @loh.

When doing evil tricks, how about replacing grep() with map()?

   @unique = map { $seen{$_->{names}}++ ? () : $_->{names} } @loh;


Oh, and don't forget to clear %seen everytime you want to run this line.
putting a "my %seen;" just in front of this line should do, most of the
time.

-- 
	Bart.

==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-anyperl-request@macperl.org