As GrandFather said, you are looking at non-trivial task. There are so many ways in which two "nested data structures" can differ, you would need to break the task down into stages:
  1. The "root" data types of the two structures have to be the same (can't compare an array to a hash)
  2. For the top-level unit, determine if the number of elements is same or different; for hashes, also determine which keys they have in common and which keys are unique to each hash
  3. Compare the values of the common elements:
    1. If the Nth elements in both arrays (or the values for key "X" in both hashes) are both scalars, do the two scalars match or not?
    2. If only one is a scalar and the other is a reference, how do you want to view that?
    3. If both are references, do they refer to the same type of thing?
      1. If so, you would probably check to see if they both actually point to the same memory address, and if they don't, recurse to compare the contents of each reference.
      2. If they point to different kinds of things, how do you want to view that?
  4. Figure out how you want to view the elements that are unique to one or the other structure, given that these things themselves could be arbitrarily complex.

Or, maybe you just need to be more explicit about the kinds of things you really want to compare (e.g. only isomorphic structures, where the possible differences are limited to "leaf-node" scalar values, or some similar constraint), and what purpose(s) would be served by your enumeration of differences (because the form of results should follow/support the intended function).


In reply to Re: Compare/Diff on nested data structures by graff
in thread Compare/Diff on nested data structures by cosmicperl

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.