NAME
Data::Difference - Compare simple hierarchical data
VERSION
version 0.113001
DESCRIPTION
Data::Difference
will compare simple data structures returning a list of details about what was added, removed or changed. It will currently handle SCALARs, HASH references and ARRAY references.
Each change is returned as a hash with the following element.
- path
-
path will be an ARRAY reference containing the hierarchical path to the value, each element in the array will be either the key of a hash or the index on an array
- a
-
If it exists it will contain the value from the first argument passed to
data_diff
. If it does not exist then this element did not exist in the first argument. - b
-
If it exists it will contain the value from the second argument passed to
data_diff
. If it does not exist then this element did not exist in the second argument.
PERL VERSION
This library should run on perls released even a long time ago. It should work on any version of perl released in the last five years.
Although it may work on older versions of perl, no guarantee is made that the minimum required version will not be increased. The version may be increased for any reason, and there is no promise that patches will be accepted to lower the minimum required perl.
SYNOPSYS
use Data::Difference qw(data_diff);
use Data::Dumper;
my %from = (Q => 1, W => 2, E => 3, X => [1,2,3], Y=> [5,6]);
my %to = (W => 4, E => 3, R => 5, => X => [1,2], Y => [5,7,9]);
my @diff = data_diff(\%from, \%to);
@diff = (
# value $a->{Q} was deleted
{ 'a' => 1, 'path' => ['Q'] },
# value $b->{R} was added
{ 'b' => 5, 'path' => ['R'] },
# value $a->{W} changed
{ 'a' => 2, 'b' => 4, 'path' => ['W'] },
# value $a->{X}[2] was deleted
{ 'a' => 3, 'path' => ['X', 2] },
# value $a->{Y}[1] was changed
{ 'a' => 6, 'b' => 7, 'path' => ['Y', 1] },
# value $b->{Y}[2] was added
{ 'b' => 9, 'path' => ['Y', 2] },
);
AUTHOR
Graham Barr <gbarr@cpan.org>
COPYRIGHT
Copyright (c) 2011 Graham Barr. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
AUTHOR
Graham Barr
CONTRIBUTORS
Graham Barr <gbarr@pobox.com>
Ricardo Signes <rjbs@semiotic.systems>
COPYRIGHT AND LICENSE
This software is copyright (c) 2025 by Graham Barr.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.