Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Detecting duplicate keywords passed in a form

by huguei (Scribe)
on Mar 21, 2003 at 14:34 UTC ( #244875=note: print w/replies, xml ) Need Help??


in reply to Detecting duplicate keywords passed in a form

something like
foreach $keyword (@keywords) {
     $dups{$keyword}++;
     if $dups{$keyword}>1 {
        # duplicate keyword!
... hugo.
  • Comment on Re: Detecting duplicate keywords passed in a form

Replies are listed 'Best First'.
Re: Re: Detecting duplicate keywords passed in a form
by diotalevi (Canon) on Mar 21, 2003 at 14:42 UTC

    That's better written using exists() and undef values for %dups. You've written more code than you had to. There's something to be said for only writing the necessary bits.

    my @kewords = ...; my %dups; for my $keyword (@keywords) { if (exists $dups{$keyword}) { # dup } else { $dups{$keyword} = undef; } }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2022-08-18 00:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?