Thread perlfaq4 - How do I compute the difference of: three arrays? (5 answers)
Opened by pktm at 2006-07-10 20:11

murphy
 2006-07-10 21:10
#68025 #68025
User since
2004-07-19
1776 Artikel
HausmeisterIn
[Homepage]
user image
Das müsste doch völlig analog zum Beispiel so funktionieren:
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[...]
my @arrays = (\@array1, \@array2, [...]);

my @union;
my @intersection;
my @difference;

my %counts;

foreach my $array (@arrays) {
    $counts{$_}++ foreach (@$array);
}

foreach my $item (keys %counts) {
    push @union, $item;
    push @{ $counts{$item} == scalar(@arrays) ? \@intersection : \@difference }, $item;
}


(Code ist ungetestet)
When C++ is your hammer, every problem looks like your thumb.

View full thread perlfaq4 - How do I compute the difference of: three arrays?