http://qs321.pair.com?node_id=244847


in reply to Detecting duplicate keywords passed in a form

Use the uniqueness property of a hash to filter duplicates.

my @keywords = keys %{{ map { lc, undef } qw(this that other foo this bar)}} ;

Updated I changed $_ => undef to lc, undef to be correctly case-insensitive

Replies are listed 'Best First'.
Re: Re: Detecting duplicate keywords passed in a form
by flounder99 (Friar) on Mar 21, 2003 at 16:36 UTC
    diotalevi's method looses the order. This maintains the order.
    my @keywords; { #closure so %temphash gets garbage collected my %temphash; foreach ( map {lc} qw(this that other foo THIS bar)) { next if exists $temphash{$_}; $temphash{$_} = undef; push @keywords, $_; } } print join " ", @keywords; ___OUTPUT____ this that other foo bar

    --

    flounder