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


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; } }