Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: How do I test the deep equality of two hash tables?

by fergal (Chaplain)
on May 22, 2005 at 13:07 UTC ( #459340=note: print w/replies, xml ) Need Help??


in reply to How do I test the deep equality of two hash tables?

Test::Deep provides deep comparisons of any data structures, including hashes. It is also capable of very advanced testing - what regular expressions do for strings, Test::Deep does for data structures.
use Test::Deep; if (eq_deeply($hash1, $hash2)) { print "they match" }

The fancy stuff comes in when you do something like

$animals = set("cat", "dog"); $people = set("john", "mary"); $a_p = set($animals, $people); print eq_deeply($structure, $a_p);
Ths is an example of testing set equality. It tests that $structure is an array with 2 elemenents (in any order) where each of those elements is an array with 2 elements, one containiing "cat" and "dog" (in any order) the other containing "john" and "mary" (in any order)

When used as part of the Test::Builder framework it gives diagnostics on where the structures differed.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2023-02-06 22:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (37 votes). Check out past polls.

    Notices?