Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Compare two arrays for uniqueness

by Kenosis (Priest)
on Dec 16, 2013 at 04:51 UTC ( #1067285=note: print w/replies, xml ) Need Help??

in reply to Compare two arrays for uniqueness

The module List::Compare lives for this (and a few other things):

use strict; use warnings; use List::Compare; my @mammals = qw/dog cat mouse horse planet/; my @sky = qw/star planet galaxy nova comet/; my $lc = List::Compare->new( \@mammals, \@sky ); my @intersection = $lc->get_intersection; print "@intersection", "\n"; # prints "planet" print scalar @intersection, "\n"; # prints 1 my @arr1 = 0 .. 5; my @arr2 = 6 .. 10; $lc = List::Compare->new( \@arr1, \@arr2 ); @intersection = $lc->get_intersection; print "@intersection", "\n"; # prints "" print scalar @intersection, "\n"; # prints 0

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (9)
As of 2016-08-31 16:17 GMT
Find Nodes?
    Voting Booth?
    The best thing I ever won in a lottery was:

    Results (433 votes). Check out past polls.