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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|