Stripping duplicates from a list

Torsten Knorr create-soft at tiscali.de
Sat Jun 14 18:52:12 BST 2008


#!/usr/bin/perl -w
#*** test_sort.pl ***#
#-------------------------------------------------
=head
On Sat, 14 Jun 2008 09:50:07 +0100 Greg McCarroll wrote:
>But Kake, his solution has all the nasty memory overhead of a hash and
>the cpu of the hashing function, why not simply reduce it down to a simple number,
>a small static array of lookup values (the same for all lists of data) and some
>simple maths.
 Kake's version is my favourite too.
 But here is my version without an hash.
=cut
#-------------------------------------------------
 use strict;
#-------------------------------------------------
 my @in = qw(
 	aubergine
 	Aubergine
 	Banana
 	carrot
 	Daikon
 	DaiKon
 	daikon
 	elephant
 );
#-------------------------------------------------
 my @out = 
 	map $_->[0],
 	grep { $_->[2] == 0 }
 	sort 
 		{
 		$b->[2] = 1 if($a->[1] eq $b->[1]);
 		$a->[1] cmp $b->[1]
 		}
 	map [$_, lc($_), 0],
 	@in;
#-------------------------------------------------
print("$_\n") for(@out);
#-------------------------------------------------
# BR Torsten


More information about the london.pm mailing list