It depends a bit on the data. Can the hashes contain any other nested data structures, or is it really just an array of plain hashes, where the only values are strings? If you could say with absolute certainty that the keys and values will never contain a certain string, such as "\0", in that case you could use that as a string to join the key/value pairs of the hashes for a string comparison. Another option might be to stringify the hashes with Data::Dumper (a core module) and compare those strings ($Data::Dumper::Sortkeys needs to be on), although I personally don't think that's a very clean solution. Another (untested) idea might be to serialize the hashrefs with Storable for a more compact representation than what Data::Dumper produces (Fletch's JSON solution and tybalt89's Data::Dump solution are the same kind of idea). And if you want to do it with absolutely no modules at all (which I wouldn't really recommend), then you'll have to code it up in Perl, looping over the hashes to compare them, stepping deeper into the data structure if necessary.

So please let us know of some more details of your data structure.


In reply to Re: Eliminate exact duplicates from array of hashes by haukex
in thread Eliminate exact duplicates from array of hashes 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.