in reply to array comparison question

Assuming the arrays are called @a1, @a2, @a3, the following ought to work (although I didn't test it). It should work correctly even if a value appears twice in a single array. This technique is trivially adaptable for different number of arrays, or different counts.
my @twice = do { my %a; map {my $a = $_; map {$a{$_}{$a}++} @$a} \@a1, \@a2, \@a3; grep {2 == keys %{$a{$_}}} keys %a; };

Replies are listed 'Best First'.
Re^2: array comparison question
by reasonablekeith (Deacon) on Aug 23, 2005 at 15:58 UTC
    it's a good solution, but I hate to see 'map' used instead of a 'for' unnecessarily, why make perl go to the trouble of building a return array if you're just going to ignore it? .
    my @twice = do { my %tracker; foreach my $a_ref (\@a1, \@a2, \@a3) { foreach my $a_value (@$a_ref) { $tracker{$a_value}{$a_ref} = undef; } } grep {2 == keys %{$tracker{$_}}} keys %tracker; };
    ---
    my name's not Keith, and I'm not reasonable.

      So long as you're using 5.8.1 or newer map in a void context won't build a return list. See perldoc perl581delta in the section "Miscellaneous Enhancements".

      (Having said that, stylistically I'm with you. :)

      --
      We're looking for people in ATL