in reply to using hash uniqueness to find the odd man

Without seeing your code, its tough to know if there is a "better algorithm." However, what you describe sounds like a very perlish solution. Assuming you have two arrays (@a and @b) and you know that one of them (@b) has an extra element, one solution would be:
@a = (1,2,4); @b = (1,2,3,4); my %seen; for (@a) { $seen{$_}++; } for (@b) { print "$_ was in \@b but not in \@a\n" unless $seen{$_}; }

Oh, I believe that this is called finding the difference of the arrays.

-Blake

Replies are listed 'Best First'.
Re: Re: using hash uniqueness to find the odd man
by novitiate (Scribe) on Jul 11, 2001 at 04:42 UTC
    my code is roughly the same -
    s/$seen{$_}++/$seen{$_} = 1;/
    almost the same,right?

    humbly,
    novitiate

    "...goodnight you princes of main(e)"  --The Cider House Rules
      I would recommend using $seen{$_}++ over $seen{$_}=1 because with the former you have additional information, such as how many times you have seen that particular item. This can be useful for detecting duplicate keys, for example.

      As such, these two are perhaps functionally the same in a narrow set of circumstances. Using the ++ approach is much more adaptable, so it should be used in preferance to simple assignment.