I think there is a module Array::Compare which will do what you want. If not, adapt following to suit you needs. Shows a couple of methods, more variations are possible as this can get complicated. Most simple is version2 when arrays are of the same size and sort order (don't have to worry about some undefined value). The below will not "blow up" if array's are of different size, but result could wind up being hard to interpret.
#!/usr/bin/perl -w use strict; my @a = qw(a b c e); my @b = qw(a b c d g); compare1 (\@a,\@b); compare2 (\@a,\@b); sub compare1 { my ($aref, $bref) = @_; my %a = map{$_=>0}@$aref; my %b = map{$_=>0}@$bref; foreach (keys %a) { $a{$_}++ if (exists ($b{$_})); } foreach (keys %b) { $b{$_}++ if (exists $a{$_}); } foreach (keys %a) { print "$_ does not exist in B\n" if !$a{$_}; } foreach (keys %b) { print "$_ does not exist in A\n" if !$b{$_}; } } sub compare2 { my ($aref, $bref) = @_; my @a = @$aref; my @b = @$bref; while (@a || @b) { my ($compa, $compb) = (shift @a, shift @b); $compa = 'undefined' if (!defined($compa)); $compb = 'undefined' if (!defined($compb)); if ($compa ne $compb) { print "$compa and $compb do not match\n"; } } } __END__ e does not exist in B g does not exist in A d does not exist in A e and d do not match undefined and g do not match

In reply to Re: Print both elements in a compare by Marshall
in thread Print both elements in a compare by Anonymous Monk

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.