You should read the documentation for Array::Compare. It's useful. It's written to answer these sorts of questions. I think you simply want to change $comp->compare to $comp->perm. This is in the module's POD. Here's a test example:

#!/usr/bin/env perl use strict; use warnings; use List::Util qw(shuffle); use Array::Compare; my @array1 = shuffle(1..100); my @array2 = shuffle(@array1); my $comp = Array::Compare->new; print "perm: ", $comp->perm(\@array1, \@array2) ? "Same elements\n" : "Different elements\n"; print "compare: ", $comp->compare(\@array1, \@array2) ? "Same elements, same order\ +n" : "Different elements or diff +erent order\n";

The shuffle gives a 1:100! chance of the lists being in the same order, I think. So for this test we can usually assume that the elements start out in dissimilar orders. But we do test for that just to be sure. If we run it the output should be:

perm: Same elements compare: Different elements or different order

So even though the elements come in a different order, the perm() method determines that we got the same elements.


Dave


In reply to Re: compare two arrays if both are equal and have same elements irrespective of their position by davido
in thread compare two arrays if both are equal and have same elements irrespective of their position by noviceuser

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.