Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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

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 universe expands...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2017-09-19 21:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (229 votes). Check out past polls.

    Notices?