rhew.org

Algorithm::Diff - Basic Functionality

All of the documented interfaces to Algorithm::Diff are built around one core function, traverse_sequences(). In addition to the lists to compare, the user supplies a key generation function and a set of callbacks. traverse_sequences() takes the two lists and applies a standard difference algorithm to them.

  traverse_sequences( \@seq1, \@seq2,
                     { MATCH => $callback,
                       DISCARD_A => $callback,
                       DISCARD_B => $callback,
                     },
                     $key_generation_function );

Callback Functions

As the difference is completed, the user's callback functions are called for each pair of elements that match or exist only in one list. The user may specify one or more of the following callback functions:

MATCH

The MATCH callback is called with indices of two matching elements in the lists.

DISCARD_A

The DISCARD_A callback is called with the index of an element in the first list that does not exist in the second.

DISCARD_B

The DISCARD_B callback is called with the index of an element in the second list that does not exist in the first.

Key Generation Function

The key generation function allows the user to provide a function that takes a list element as an argument and returns a key. The difference is then calculated using only the key, not the entire element.

Other Algorithm::Diff Functions

The following functions are also provided by Algorithm::Diff:

LCS

LCS (Longest Common Subsequence) returns the longest sequence of elements common to both user specified lists.

diff

diff returns a list of optimized deletion and addition instructions for transforming the first user specified list into the second.

rhew.org (c) 2001 James Rhew