Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: comparing nested data structures

by BrowserUk (Pope)
on Nov 02, 2011 at 11:33 UTC ( #935358=note: print w/replies, xml ) Need Help??

in reply to comparing nested data structures

would like to join indentical sub-trees

It kind of depends what you mean by "identical subtrees".

If by identical, you mean that any substructure references below the top level are references to the same hash or array , then simply stringifying both hashes (or both arrays) and comparing the string for equality will tell you if they are identical or not. And it will be considerably faster than full tree traversal methods.

AFAIK (and my ability to quickly verify), any hash that contains the same keys and values will stringify(*) to the same string, regardless of either the order in which the hash was constructed or whether it has at anytime contains other keys subsequently removed. So there should be no need to sort the keys.

If you would consider two different arrays or hashes that contains the same data as "identical", then it would be necessary to recursively stringify contained references bottom up. It might well still be quicker than an element by element recursive comparison if all you need is a boolean yes/no rather than a blow-by-blow differences found.

(*using suitable delimiters.)

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://935358]
[stevieb]: I'm checking some other versions. This is a little frightening
[pryrt]: Sorry, my bad: it was't done downloading when I did the sha1sum... now I match your 309ad... value
[stevieb]: I'll see how to get in touch with someone and advise that there's an issue. Thanks for helping me confiirm pryrt!

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (12)
As of 2017-03-29 21:02 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (353 votes). Check out past polls.