Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2018-10-19 17:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When I need money for a bigger acquisition, I usually ...














    Results (110 votes). Check out past polls.

    Notices?