in reply to Finding duplicate keys

If you know the keys are unique within each table, one shortcut might be to notice the second time you saw each key in a scan of both:
my @dups = do { my %count; grep ++$count{$_} == 2, @keys_from_one, @keys_from_two; };

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re: •Re: Finding duplicate keys
by pg (Canon) on Apr 04, 2003 at 18:44 UTC
    This piece of code really has a performance issue, as internally it uses "brutal force". I bench marked this against Ovid's code, this one took 93 seconds when Ovid's only took 6 seconds, for the same array size.
    @keys1 = (1..1000000); #array names would be modified to match the plu +g-in code for (my $a = 2; $a < 1000000; $a += 2) { push @keys2, $a; ##array names would be modified to match the plug +-in code } my $t0 = time(); #plug the code here print time() - $t0;