jbrugger has asked for the wisdom of the Perl Monks concerning the following question:
*update*# If my datasets contain # @1 = 1,2,3,4,5 # @2 = 2,3,6,7,8,8,8,9,10 # @3 = 5,6,2,3 # # the result should be: 2,3 # my %intersection; my @result; foreach my $dataArray(@AllArraysIHave) { my %lookuptable; foreach(@{$dataArray}) { if (!$lookuptable{$_}) { $lookuptable{$_} = 1; $intersection{$_}++; } } } my $amnt = scalar(@AllArraysIHave); foreach my $key (keys %intersection) { if ($intersection{$key} == $amnt) { push @result, $key; } } return \@result;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Getting the intersection of n collections.
by basje (Beadle) on Oct 11, 2006 at 12:30 UTC | |
by johngg (Canon) on Oct 11, 2006 at 13:58 UTC | |
|
Re: Getting the intersection of n collections.
by dtr (Scribe) on Oct 11, 2006 at 11:59 UTC | |
|
Re: Getting the intersection of n collections.
by jdporter (Paladin) on Oct 11, 2006 at 14:17 UTC | |
|
Re: Getting the intersection of n collections.
by japhy (Canon) on Oct 11, 2006 at 12:08 UTC | |
|
Re: Getting the intersection of n collections.
by lima1 (Curate) on Oct 11, 2006 at 12:10 UTC | |
|
Re: Getting the intersection of n collections.
by GrandFather (Saint) on Oct 12, 2006 at 07:59 UTC | |
by Anonymous Monk on Oct 12, 2006 at 09:41 UTC | |
|
Re: Getting the intersection of n collections.
by Anonymous Monk on Oct 12, 2006 at 07:43 UTC |