1Array::Diff(3)        User Contributed Perl Documentation       Array::Diff(3)
2
3
4

NAME

6       Array::Diff - Find the differences between two arrays
7

SYNOPSIS

9           my @old = ( 'a', 'b', 'c' );
10           my @new = ( 'b', 'c', 'd' );
11
12           my $diff = Array::Diff->diff( \@old, \@new );
13
14           $diff->count   # 2
15           $diff->added   # [ 'd' ];
16           $diff->deleted # [ 'a' ];
17

DESCRIPTION

19       This module compares two pre-sorted arrays and returns the added or
20       deleted elements in two separate arrays.  It's a simple wrapper around
21       Algorithm::Diff.
22
23       Note: the arrays must be sorted before you call "diff".
24
25       And if you need more complex array tools, check Array::Compare.
26

METHODS

28       new ()
29           Create a new "Array::Diff" object.
30
31       diff ( OLD, NEW )
32           Compute the differences between two arrays.  The results are stored
33           in the "added", "deleted", and "count" properties that may be
34           examined using the corresponding methods.
35
36           This method may be invoked as an object method, in which case it
37           will recalculate the differences and repopulate the "count",
38           "added", and "removed" properties, or as a static method, in which
39           case it will return a newly-created "Array::Diff" object with the
40           properties set appropriately.
41
42       added ( [VALUES ] )
43           Get or set the elements present in the "NEW" array and absent in
44           the "OLD" one at the comparison performed by the last "diff()"
45           invocation.
46
47       deleted ( [VALUES] )
48           Get or set the elements present in the "OLD" array and absent in
49           the "NEW" one at the comparison performed by the last "diff()"
50           invocation.
51
52       count ( [VALUE] )
53           Get or set the total number of added or deleted elements at the
54           comparison performed by the last "diff()" invocation.  This count
55           should be equal to the sum of the number of elements in the "added"
56           and "deleted" properties.
57

SEE ALSO

59       Array::Compare - performs the same function as this module, but has
60       options for controlling how it works.
61
62       List::Compare - similar functionality, but again with more options.
63
64       Algorithm::Diff - the underlying implementation of the diff algorithm.
65       If you've got Algorithm::Diff::XS installed, that will be used.
66
67       YAML::Diff - find difference between two YAML documents.
68
69       HTML::Differences - find difference between two HTML documents.  This
70       uses a more sane approach than HTML::Diff.
71
72       XML::Diff - find difference between two XML documents.
73
74       Hash::Diff - find the differences between two Perl hashes.
75
76       Data::Diff - find difference between two arbitrary data structures.
77
78       Text::Diff - can find difference between two inputs, which can be data
79       structures or file names.
80

AUTHOR

82       Daisuke Murase <typester@cpan.org>
83
85       Copyright (c) 2009 by Daisuke Murase.
86
87       This program is free software; you can redistribute it and/or modify it
88       under the same terms as Perl itself.
89
90       The full text of the license can be found in the LICENSE file included
91       with this module.
92
93
94
95perl v5.34.0                      2021-07-22                    Array::Diff(3)
Impressum