For arrays you could compute the intersection, and if the size of the intersection array is the same size as both input arrays, then they are identical. List::Compare can be used for getting the intersection.

You could have your own compare() subroutine which directs to the corret comparison depending on what sort of data is passed and how you want to define 'the same'.

I didn't find any problem when comparing with hashes where in keys are in whatever order. I accept that my understanding is wrong and certainly it should not match
Actually the two hashes you give *are* the same. Hash key/value pairs are not stored in the order they are input, and your key/value pairs are the same...

I haven't had much time to look into the pros/cons of it yet, and i don't know how uesful it might be, but as of 5.10 (i think, at least my 5.8.8 doesn't have the feature) the ~~ smartmatch operator can compare hashes and arrays ( perlfaq4 ), although it seems to have the same issues about ordering of elements as OP and rata have already mentioned...

As usual, it is all a matter of semantics, and 'identical' can be defined several ways, so like i said, i would have my own little sub that does exactly what *i* define as identical. HTH.

Just a something something...

In reply to Re: Compare Hashes and Arrays by BioLion
in thread Compare Hashes and Arrays by kalyanrajsista

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.