Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Detecting duplicate keywords passed in a form

by diotalevi (Canon)
on Mar 21, 2003 at 13:12 UTC ( #244847=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://244847]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2022-08-18 01:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?