use Data::Compare; my $h1 = { 'foo' => [ 'bar', 'baz' ], 'FOO' => [ 'one', 'two' ] }; my $h2 = { 'foo' => [ 'bar', 'barf' ], 'FOO' => [ 'one', 'two' ] }; my @a1 = ('one', 'two'); my @a2 = ('bar', 'baz'); my %v = ( 'FOO', \@a1, 'foo', \@a2 ); # simple procedural interface print 'structures of $h1 and \%v are ', Compare($h1, \%v) ? "" : "not ", "identical.\n"; print 'structures of $h1 and $h2 are ', Compare($h1, $h2, { ignore_hash_keys => [qw(foo)] }) ? '' : 'not ', "close enough to identical.\n"; # OO usage my $c = new Data::Compare($h1, \%v); print 'structures of $h1 and \%v are ', $c->Cmp ? "" : "not ", "identical.\n"; # or my $c = new Data::Compare; print 'structures of $h and \%v are ', $c->Cmp($h1, \%v) ? "" : "not ", "identical.\n";
A few data types are treated as special cases:
$r = qr/abc/i; $s = qr/abc/i; Compare($r, $s);
and the following won't, despite them matching *exactly* the same text:
$r = qr/abc/i; $s = qr/[aA][bB][cC]/; Compare($r, $s);
Sorry, that's the best we can do.
You may also customise how we compare structures by supplying options in a hashref as a third parameter to the "Compare()" function. This is not yet available through the OO-ish interface. These options will be in force for the *whole* of your comparison, so will apply to structures that are lurking deep down in your data as well as at the top level, so beware!
$x = \$y; $y = \$x; Compare([$x, $y], [$x, $y]);
And on a sort-of-related note, if you try to compare insanely deeply nested structures, the module will spit a warning. For this to affect you, you need to go around a hundred levels deep though, and if you do that you have bigger problems which I can't help you with ;-)
Plugins are *not* available when running in ``taint'' mode. You may also make it not load plugins by providing an empty list as the argument to import() - ie, by doing this:
use Data::Compare ();
A couple of functions are provided to examine what goodies have been made available through plugins:
use Data::Compare (); Data::Compare->register_plugins;
or you could call it as a function if that floats your boat.
Plugins are unavailable if you can't change to the current directory. This might happen if you started your process as a priveleged user and then dropped priveleges. If this affects you, please supply a portable patch with tests.
Bug reports should be made on Github or by email.
Portions by David Cantrell <david@cantrell.org.uk>
Some parts copyright 2003 - 2014 David Cantrell.
Seeing that Fabien seems to have disappeared, David Cantrell has become a co-maintainer so he can apply needed patches. The licence, of course, remains the same. As the ``perl licence'' is ``Artistic or GPL, your choice'', you can find them as the files ARTISTIC.txt and GPL2.txt in the distribution.