I would not advise using Data::Diff - in addition to the problem that you have noticed, it doesn't handle circularities in data structures (always a risk in nested data structures)
You may want to try Test::Deep. If you don't want to include the Perl testing framework (e.g. Test::More etc) it has a version called Test::Deep::NoTest. It should give you detailed output on the differences between two structures and plays nicely with hashes, arrays, objects, bags, and a host of other data structure variants.
It uses a lot of exports and syntactic sugar. If that is not to your taste, you could always write some wrapper functions around it. Place those functions in their own module, and use Test::Deep (or Test::Deep::NoTest only in that module. It would be a lot easier than writing your own module. As has already been stated, writing general purpose data exploration algorithms is non-trivial.
This is one of those problems that looks simple, but isn't. Aside from the points already mentioned by grandfather and graff, a general purpose data comparison algorithm has to (a) detect and gracefully handle circularities in a data graph (b) decide whether or not to treat object references as opaque (c) call a list of selected methods (possibly with parameters) to compare opaque objects.
If you are using the comparison for business or scientific reports, a hand-rolled data comparison module would also have to take into account several questions about the interpretation of differences. Do all keys/array elements matter? They might not if some of the data is transient and you only care about the part that persists when you dump things out to YAML or XML. Does order of elements in an array matter? If the array is used to implement a "bag" it shouldn't. If hash keys are missing, does that matter? Should hash keys be compared if one of the hashes assigns undef? If you only want to compare "known" or "applicable" data, then probably not.
If Test::Deep doesn't do what you want, perhaps you could describe the specific goals and data structures for which you want to do comparisons. CPAN has many, many data comparison modules for specific kinds of data structures. With a bit more focus to your question, we might be able to suggest one of them.
Best, beth
In reply to Re: Compare/Diff on nested data structures
by ELISHEVA
in thread Compare/Diff on nested data structures
by cosmicperl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |