in reply to intersection of N arrays
Based on that you could:@union = @intersection = @difference = (); %count = (); foreach $element (@array1, @array2) { $count{$element}++ } foreach $element (keys %count) { push @union, $element; push @{ $count{$element} > 1 ? \@intersection : \@difference } +, $element; }
sub intersection{ my(%count,@res); for(map @$_,@_){$count{$_}++} for(keys %count){push @res,$_ if $count{$_}==@_} @res; } @a=intersection(\@b,\@c,\@d);
|
---|