in reply to Finding duplicate keys
If you've got them in two arrays, don't use a nested loop as that is over 3 million comparisons that you'll have to make. Instead, use a hash for one of them.
my %search; @search{ @keys2 } = undef; my @found; foreach my $key (@keys1) { push @found => $key if exists $search{$key}; }
When that's done, @found will have the duplicate keys. You'll only have a few thousand iterations instead of a few million.
Cheers,
Ovid
New address of my CGI Course.
Silence is Evil (feel free to copy and distribute widely - note copyright text)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Finding duplicate keys
by diotalevi (Canon) on Apr 04, 2003 at 18:57 UTC |