in reply to Mystery of missing functions
Apart from List::Utils that others already mentioned I'd like to add that if you want to do union, intersection or difference you should most likely be using a hash, not an array anyway. A hash with empty values, but a hash nevertheless.
# is element $a in the set? exists $set{$a} # remove $a from the set delete $set{$a}; # add $a to the set $set{$a} = undef; # get the list of elements in the set keys %set # create the union %union = (%set1, %set2); # create the intersection for (keys %set1) { $intersect{$_} = undef if exists $set2{$_}; } # create the difference for (keys %set1) { $diff{$_} = undef unless exists $set2{$_}; } for (keys %set2) { $diff{$_} = undef unless exists $set1{$_}; }
This will be much quicker than anything you could build with arrays.
|
|---|