in reply to Re: Finding duplicate keys
in thread Finding duplicate keys

Why are you using eq in one comparison and > in the other? Besides, using cmp you can avoid the duplicate comparison altogether. Your looping condition is not robust, either.
my @array1 = sort <$file1>; my @array2 = sort <$file2>; my ($l,$r) = (0) x 2; while ($l < @array1 and $r < @array2) { if(my $b = $array1[$l] cmp $array2[$r]) { ++($b == 1 ? $r : $l); } else { print "Dupe: $array1[$l]\n"; ++$l; ++$r; } }

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: Re^2: Finding duplicate keys
by antirice (Priest) on Apr 06, 2003 at 01:12 UTC
    Thanks for pointing out the inadequacies of my code. I didn't think of using cmp as I haven't used it very frequently. :-/

    antirice    
    The first rule of Perl club is - use Perl
    The
    ith rule of Perl club is - follow rule i - 1 for i ] 1