Stripping duplicates from a list

David Cantrell david at cantrell.org.uk
Thu Jun 12 16:39:36 BST 2008


On Thu, Jun 12, 2008 at 04:16:17PM +0100, Kake L Pugh wrote:

> Hello.  I have a list of strings of variable capitalisation, for example:
> 
> aubergine
> Aubergine
> Banana
> carrot
> Daikon
> DaiKon
> daikon
> elephant
> 
> What I want to do is strip out the duplicates - i.e. those strings
> which differ only by capitalisation - but keep by preference one of
> the versions that has a capital letter at the beginning...

@foo = sort { uc($a) cmp uc($b) } values %{{ do {
    my %foo = ();
    foreach(sort @foo) {
        $foo{uc($_)} = $_ unless(exists($foo{uc($_)}));
    } 
    %foo;
}}};

-- 
David Cantrell | Enforcer, South London Linguistic Massive

Are you feeling bored? depressed? slowed down?  Evil Scientists may
be manipulating the speed of light in your vicinity.  Buy our patented
instructional video to find out how, and maybe YOU can stop THEM


More information about the london.pm mailing list