Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

How do I compute the difference of two arrays? How do I compute the intersection of two arrays?

by faq_monk (Initiate)
on Oct 08, 1999 at 00:20 UTC ( #611=perlfaq nodetype: print w/replies, xml ) Need Help??

Current Perl documentation can be found at

Here is our local, out-dated (pre-5.6) version:

Use a hash. Here's code to do both and more. It assumes that each element is unique in a given array:

    @union = @intersection = @difference = ();
    %count = ();
    foreach $element (@array1, @array2) { $count{$element}++ }
    foreach $element (keys %count) {
        push @union, $element;
        push @{ $count{$element} > 1 ? \@intersection : \@difference }, $element;

Log In?

What's my password?
Create A New User
[1nickt]: hm, what did I do wrong? No download link in a code secrtion of a node I just posted ...
[Corion]: I see a download link there?
[Corion]: (at least the curl stuff is in a download link)
[Corion]: Also, I think the OPs problem is on their intranet and not on the internet (also, they should likely use WWW::Mechanize instead, which knows about cookie)
[1nickt]: yes, could be.
[1nickt]: I don;t see the link , definitely, after reloading the node
[1nickt]: Is it possible to disable it?
[Discipulus]: if you mean [download] after the code it is there 1nickt

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (10)
As of 2017-05-23 18:14 GMT
Find Nodes?
    Voting Booth?