in reply to Re: array comparison question
in thread array comparison question

If we go with the assumption that an element never occurs more than once in a single array, we don't need to track the arrays seperately, and can use Perl's array flattening:

my %present; for my $a ( @array1, @array2, @array3 ) { $present{ $a }++ } my @only_two = grep $present{ $_ } == 2, keys %present;

If we have to deal with multiples in any of the arrays:

use List::MoreUtils qw(uniq); my %present = (); for my $a ( uniq(@array1), uniq(@array2), uniq(@array3) ) { $present{ +$a }++ } my @only_two = grep $present{ $_ } == 2, keys %present;