Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Mystery of missing functions

by Jenda (Abbot)
on Oct 27, 2006 at 21:47 UTC ( #581027=note: print w/replies, xml ) Need Help??

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://581027]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2018-12-10 04:16 GMT
Find Nodes?
    Voting Booth?
    How many stories does it take before you've heard them all?

    Results (47 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!