Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Need a test for deep equality

by rinceWind (Monsignor)
on Apr 21, 2002 at 09:49 UTC ( #160859=note: print w/replies, xml ) Need Help??

in reply to Need a test for deep equality

Update: What I didn't specify, but perhaps should have, is that parts of the data structure are blessed object references, and I want to compare the guts of the objects.


Data::DumperHashes not consistently serialised
Test::MoreOnly does a shallow comparison.
Tie::IxHashSolves a different problem. Anonymous hashes cannot be tied
FreezeThawOnly copes with shallow structures
Struct::CompareDoes not handle references
Recursive comparison by thraxilDoes not handle object references
Data::CompareDoes not handle references

Conclusion: either fix Data::Dumper or roll my own compare routine :-<.

Update 2: I have been looking further at Test::More. There are numerous versions floating about, owing to the way in which people have used it to package up their tests in their own modules.

The definitive Test::More on CPAN has a function eq_hash, which suffers from the same syndrome as Data::Dumper when it comes to ordering of keys.

Update 3: simonm++ The module Class::MakeMethods::Utility::Ref does the business! Shame about the name - something as useful should not IMO have a module name 4 levels down, with no clue as to what it can do.

Replies are listed 'Best First'.
Re: Re: Need a test for deep equality
by thor (Priest) on Apr 21, 2002 at 18:36 UTC
    I have to wonder if you could canoncalize the hashes. A simple "alphabetize the keys at each level" comes to mind. This could be expensive for large/deep hashes, but, it may be worth it to you.
Re^2: Need a test for deep equality
by Anonymous Monk on Aug 01, 2020 at 12:57 UTC

    This is an old thread, which is probably the reason for this omission, but... Test::More has an is_deeply() that works for my purposes (no object references). The docs for Test::More also recommend other Perl modules that will handle object references, etc.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://160859]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2022-01-18 08:32 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (52 votes). Check out past polls.