1Array::Diff(3) User Contributed Perl Documentation Array::Diff(3)
2
3
4
6 Array::Diff - Find the differences between two arrays
7
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
19 This module compares two arrays and returns the added or deleted
20 elements in two separate arrays. It's a simple wrapper around
21 Algorithm::Diff.
22
23 And if you need more complex array tools, check Array::Compare.
24
26 new ()
27 Create a new "Array::Diff" object.
28
29 diff ( OLD, NEW )
30 Compute the differences between two arrays. The results are stored
31 in the "added", "deleted", and "count" properties that may be
32 examined using the corresponding methods.
33
34 This method may be invoked as an object method, in which case it
35 will recalculate the differences and repopulate the "count",
36 "added", and "removed" properties, or as a static method, in which
37 case it will return a newly-created "Array::Diff" object with the
38 properies set appropriately.
39
40 added ( [VALUES ] )
41 Get or set the elements present in the "NEW" array and absent in
42 the "OLD" one at the comparison performed by the last "diff()"
43 invocation.
44
45 deleted ( [VALUES] )
46 Get or set the elements present in the "OLD" array and absent in
47 the "NEW" one at the comparison performed by the last "diff()"
48 invocation.
49
50 count ( [VALUE] )
51 Get or set the total number of added or deleted elements at the
52 comparison performed by the last "diff()" invocation. This count
53 should be equal to the sum of the number of elements in the "added"
54 and "deleted" properties.
55
57 Algorithm::Diff
58
60 Daisuke Murase <typester@cpan.org>
61
63 Copyright (c) 2009 by Daisuke Murase.
64
65 This program is free software; you can redistribute it and/or modify it
66 under the same terms as Perl itself.
67
68 The full text of the license can be found in the LICENSE file included
69 with this module.
70
71
72
73perl v5.28.1 2010-10-08 Array::Diff(3)