At first I thought "intersection", but I remembered Re: Re: How do I compare two arrays? by Corion where Corion mentions symmetric difference between two sets. Take a look.

Update: Here's another example Symmetric_difference

#!/usr/bin/perl use strict; use warnings; my @a = qw( a b c ); my @b = qw( a b c d ); # Get the individual differences. my @a_minus_b = setminus(\@a, \@b); my @b_minus_a = setminus(\@b, \@a); # merge then together and remove possible duplicates my @symmetric_difference = uniq(@a_minus_b, @b_minus_a); # Present our results. print 'List A: ', join(', ', @a), "\nList B: ", join(', ', @b), "\nA \\ B: ", join(', ', @a_minus_b), "\nB \\ A: ", join(', ', @b_minus_a), "\nSymmetric difference: ", join(', ', @symmetric_difference), "\n"; # Takes two array references. Returns a list of elements in the first # array that aren't in the second. sub setminus { my ($a, $b) = @_; # Convert $b to hash keys, so it's easier to search. my %b; @b{@$b} = (); return grep !exists $b{$_}, @$a; } # take a list and return only uniq items sub uniq { my %saw; return grep !$saw{$_}++, @_; }

In reply to Re: Compare arrays by Khen1950fx
in thread Compare arrays by japhmi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.