Array::Diff(3pm)

Array::Diff3pm

Find the differences between two arrays

Usage

    my @old = ( 'a', 'b', 'c' );
    my @new = ( 'b', 'c', 'd' );
    my $diff = Array::Diff->diff( \@old, \@new );
    $diff->count   # 2
    $diff->added   # [ 'd' ];
    $diff->deleted # [ 'a' ];

Overview

This module compares two pre-sorted arrays and returns the added or deleted elements in two separate arrays. It's a simple wrapper around Algorithm::Diff.

Note: the arrays must be sorted before you call "diff".

And if you need more complex array tools, check Array::Compare.

Methods

new ()

Create a new "Array::Diff" object.

diff ( OLD, NEW )

Compute the differences between two arrays. The results are stored in the "added", "deleted", and "count" properties that may be examined using the corresponding methods.

This method may be invoked as an object method, in which case it will recalculate the differences and repopulate the "count", "added", and "removed" properties, or as a static method, in which case it will return a newly-created "Array::Diff" object with the properties set appropriately.

added ( [VALUES ] )

Get or set the elements present in the "NEW" array and absent in the "OLD" one at the comparison performed by the last "diff()" invocation.

deleted ( [VALUES] )

Get or set the elements present in the "OLD" array and absent in the "NEW" one at the comparison performed by the last "diff()" invocation.

count ( [VALUE] )

Get or set the total number of added or deleted elements at the comparison performed by the last "diff()" invocation. This count should be equal to the sum of the number of elements in the "added" and "deleted" properties.

Releases

8 releases since Debian 6.0 (Squeeze); the text changed 4 times.

  1. 6.0
  2. 7–8
  3. 9–10
  4. 11
  5. 12–13

Author

Daisuke Murase <[email protected]>

From libarray-diff-perl 0.09-2 in Debian 13 (Trixie). Parsed by carta from the page's man source.