Data::Difference - Compare simple hierarchical data
version 0.112850
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] }, );
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.
Data::Difference
Each change is returned as a hash with the following element.
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
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.
data_diff
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.
Graham Barr <gbarr@cpan.org>
<gbarr@cpan.org>
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.
To install Data::Difference, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Difference
CPAN shell
perl -MCPAN -e shell install Data::Difference
For more information on module installation, please visit the detailed CPAN module installation guide.