this is quite close but then I'd need to go throught one of the lists one more time :-/

I think you have to :)

#!/usr/bin/perl -- use strict; use warnings; use Data::Dump; my @source=(1, 2, 3, 4, 5, 7); my @target=(0, 1, 3, 4, 6); my (@union, @intersection, @difference); my %count = (); foreach my $element (@source, @target) { $count{$element}++ } foreach my $element (keys %count) { push @union, $element; push @{ $count{$element} > 1 ? \@intersection : \@difference }, $e +lement; } dd \@source, \@target; dd \@union; dd \@intersection; dd \@difference; my @values_in_target_not_in_source = do { my %fuf; @fuf{ @union } = undef; delete @fuf{ @target }; keys %fuf; }; my @values_in_source_not_in_target = do { my %fuf; @fuf{ @union } = undef; delete @fuf{ @source }; keys %fuf; }; dd \@values_in_target_not_in_source , \@values_in_source_not_in_target + ; __END__ ([1 .. 5, 7], [0, 1, 3, 4, 6]) [6, 4, 1, 0, 3, 7, 2, 5] [4, 1, 3] [6, 0, 7, 2, 5] ([7, 2, 5], [6, 0])

In reply to Re: compare arrays, and list the difference by Anonymous Monk
in thread compare arrays, and list the difference by iza

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.