GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Array::Diff(3) User Contributed Perl Documentation Array::Diff(3)

Array::Diff - Find the differences between two arrays

    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' ];

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.

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.

Array::Compare - performs the same function as this module, but has options for controlling how it works.

List::Compare - similar functionality, but again with more options.

Algorithm::Diff - the underlying implementation of the diff algorithm. If you've got Algorithm::Diff::XS installed, that will be used.

YAML::Diff - find difference between two YAML documents.

HTML::Differences - find difference between two HTML documents. This uses a more sane approach than HTML::Diff.

XML::Diff - find difference between two XML documents.

Hash::Diff - find the differences between two Perl hashes.

Data::Diff - find difference between two arbitrary data structures.

Text::Diff - can find difference between two inputs, which can be data structures or file names.

Daisuke Murase <typester@cpan.org>

Copyright (c) 2009 by Daisuke Murase.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.

2019-05-10 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.