Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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


Comment on Re: Compare two arrays for uniqueness
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (17)
As of 2014-09-17 17:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (92 votes), past polls