David Cantrell > Data-Compare-0.05 > Data::Compare

Download:
Data-Compare-0.05.tar.gz

Dependencies

Annotate this POD

Related Modules

Data::Dumper
List::Compare
Array::Compare
Test::More
XML::Parser
Params::Validate
Test::LectroTest
Carp::Assert
Data::Denter
XML::Twig
more...
By perlmonks.org

CPAN RT

Open  0
Report a bug
Module Version: 0.05   Source   Latest Release: Data-Compare-1.2101

NAME ^

Data::Compare - compare perl data structures

SYNOPSIS ^

    use Data::Compare;

    my $h = { 'foo' => [ 'bar', 'baz' ], 'FOO' => [ 'one', 'two' ] };
    my @a1 = ('one', 'two');
    my @a2 = ('bar', 'baz');
    my %v = ( 'FOO', \@a1, 'foo', \@a2 );

    # simple procedural interface
    print 'structures of $h and \%v are ',
      Compare($h, \%v) ? "" : "not ", "identical.\n";

    # OO usage
    my $c = new Data::Compare($h, \%v);
    print 'structures of $h and \%v are ',
      $c->Cmp ? "" : "not ", "identical.\n";
    # or
    my $c = new Data::Compare;
    print 'structures of $h and \%v are ',
      $c->Cmp($h, \%v) ? "" : "not ", "identical.\n";

DESCRIPTION ^

Compare two perl data structures recursively. Returns 0 if the structures differ, else returns 1.

A few data types are treated as special cases:

Scalar::Properties objects

If you compare a scalar and a Scalar::Properties, then they will be considered the same if the two values are the same, regardless of the presence of properties. If you compare two Scalar::Properties objects, then they will only be considered the same if the values and the properties match.

Compiled regular expressions, eg qr/foo/

These are stringified before comparison, so the following will match:

    $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]/i;
    Compare($r, $s);

Sorry, that's the best we can do.

CODE and GLOB references

These are assumed not to match unless the references are identical - ie, both are references to the same thing.

AUTHOR ^

Fabien Tassin fta@sofaraway.org

Copyright (c) 1999-2001 Fabien Tassin. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Portions copyright 2003 David Cantrell david@cantrell.org.uk

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, and all communications about this module should be CCed to Fabien in case he ever returns and wants his baby back.

SEE ALSO ^

perl(1), perlref(1)