Stripping duplicates from a list

Torsten Knorr create-soft at tiscali.de
Sun Jun 15 16:12:48 BST 2008


#!/usr/bin/perl -w
#*** sort_v2.pl ***#
#-------------------------------------------------
 use strict;
#-------------------------------------------------
# A other version without hash.
# More classical style :-).
#-------------------------------------------------
 my @in = qw(
 aubergine	Kake		Xyz		abcdefg
 Aubergine	Torsten		daikon		Greg
 elephant		007		Barry		Greg
 kake		torsten		13.6.2008	Greg
 Banana		TORSTEN	aBcDeFg		torsteN
 carrot 		xyz		Greg		ELEPHANT
 Daikon		007		Greg		13.6.2008
 DaiKon		bArRy		13:6:2008	banana
 );
#-------------------------------------------------
 my @temp = map [$_, lc($_)], @in;
 my @out;
 LOOP: for(my $i = 0; $i <= $#temp; $i++){
 	for(my $p = $i + 1; $p <= $#temp; $p++){
 		if($temp[$i]->[1] eq $temp[$p]->[1]){next(LOOP)}
 		} 
# The last item is the winner.
 	push(@out, $temp[$i]->[0]);
 	}
#-------------------------------------------------
print("$_\n") for sort @out;
#-------------------------------------------------
# BR Torsten


More information about the london.pm mailing list