Graham Barr > Data-Difference > Data::Difference

Download:
Data-Difference-0.112850.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  1
Open  0
View/Report Bugs
Module Version: 0.112850   Source  

NAME ^

Data::Difference - Compare simple hierarchical data

VERSION ^

version 0.112850

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] },
  );

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.

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.

syntax highlighting: