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

This was my first thought too, it only works if you don't have the same value in any of the arrays more than once.
my @array1 = (1,2,2); # 2 would be in the final array my @array2 = (1); my @array3 = (1);
---
my name's not Keith, and I'm not reasonable.

Replies are listed 'Best First'.
Re^3: array comparison question
by lidden (Curate) on Aug 23, 2005 at 14:49 UTC
    Modifying Fletch answer a little:
    my @array1 =( 1, 3, 6, 8); my @array2 =( 1, 2, 3, 4, 4); my @array3 =( 1, 2, 3, 5, 6); my %present; my @arrays = ( \@array1, \@array2, \@array3); for my $i ( 0 .. @arrays - 1) { $present{ $_ }{ $i } = 1 for @{ $arrays[ $i ] }; } my @only_two = grep { 2 == scalar keys %{$present{ $_ }} } keys %pre +sent; print "@only_two\n";
Re^3: array comparison question
by spiritway (Vicar) on Aug 24, 2005 at 05:03 UTC

    OK, then how about removing duplicates before you check the arrays?