<?xml version="1.0" encoding="windows-1252"?>
<node id="577594" title="Re: Getting the intersection of n collections." created="2006-10-11 08:10:29" updated="2006-10-11 04:10:29">
<type id="11">
note</type>
<author id="525442">
lima1</author>
<data>
<field name="doctext">
If the array may NOT have the same value multiple times, then this (intersect is taken and slightly modified from the perl cookbook-one must be careful these days ;) ) should work:

&lt;c&gt;
my @a = ( [ 1,2,3,4,5] ,
          [2,3,6,7,8,9,10],
          [5,6,2,3], );

my @b = @{$a[0]};

sub intersect{    
   my (%union, %isect);     
   foreach my $e (@_) { $union{$e}++ &amp;&amp; $isect{$e}++ }
   return keys %isect
}

foreach my $a_ref (@a) {
    @b = intersect(@$a_ref, @b);
}
&lt;/c&gt;

UPDATE: only works for unduplicated items!</field>
<field name="root_node">
577590</field>
<field name="parent_node">
577590</field>
</data>
</node>
