Notice that you pass references to the two arrays to the comparison method.

Internally the comparator compares the two arrays by using join to turn both arrays into strings and comparing the strings using eq. In the joined strings, the elements of the original arrays are separated with the ^G character. This can cause problems if your array data contains ^G characters as it is possible that two different arrays can be converted to the same string.

To avoid this, it is possible to override the default separator character, either by passing and alternative to the new function

my $comp = Array::Compare->new(Sep => '|');

or by changing the separator for an existing comparator object

$comp->Sep('|');

In general you should choose a separator character that won't appear in your data.

You can also control whether or not whitespace within the elements of the arrays should be considered significant when making the comparison. The default is that all whitespace is significant. The alternative is for all consecutive white space characters to be converted to a single space for the pruposes of the comparison. Again, this can be turned on when creating a comparator object:

my $comp = Array::Compare->new(WhiteSpace => 0);

or by altering an existing object:

$comp->WhiteSpace(0);

You can also control whether or not the case of the data is significant in the comparison. The default is that the case of data is taken into account. This can be changed in the standard ways when creating a new comparator object:

my $comp = Array::Compare->new(Case => 0);

or by altering an existing object:

$comp->Case(0);

In addition to the simple comparison described above (which returns true if the arrays are the same and false if they're different) there is also a full comparison which returns a list containing the indexes of elements which differ between the two arrays. If the arrays are the same it returns an empty list. In scalar context the full comparison returns the length of this list (i.e. the number of elements that differ). You can access the full comparison in two ways. Firstly, there is a DefFull attribute. If this is true then a full comparison if carried out whenever the compare method is called.

For symmetry, there is also a direct method to use to call the simple comparison.

$comp->simple_compare(\@arr1, \@arr2);

The final complication is the ability to skip elements in the comparison. If you know that two arrays will always differ in a particular element but want to compare the arrays ignoring this element, you can do it with Array::Compare without taking array slices. To do this, a comparator object has an optional attribute called Skip which is a reference to a hash. The keys in this hash are the indexes of the array elements and the values should be any true value for elements that should be skipped.

For example, if you want to compare two arrays, ignoring the values in elements two and four, you can do something like this:

Flag that indicates whether or not whitespace is significant in the comparison. If this value is false then all multiple whitespace characters are changed into a single space before the comparison takes place. Default is 1 (whitespace is significant).

Flag which indicates whether the default comparison is simple (just returns true if the arrays are the same or false if they're not) or full (returns an array containing the indexes of the columns that differ). Default is 0 (simple comparison).

Compare the values in two arrays and return a data indicating whether the arrays are the same. The exact return values differ depending on the comparison method used. See the descriptions of simple_compare and full_compare for details.

Uses the value of DefFull to determine which comparison routine to use.

Checks each individual column. In scalar context returns the number of columns that differ (zero if the arrays are the same). In list context returns an list containing the indexes of the columns that differ (an empty list if the arrays are the same).

Uses the values of 'Sep' and 'WhiteSpace' to influence the comparison.

Note: If the two arrays are of different lengths then this method just returns the indexes of the elements that appear in one array but not the other (i.e. the indexes from the longer array that are beyond the end of the shorter array). This might be a little counter-intuitive.

Check to see if one array is a permutation of the other (i.e. contains the same set of elements, but in a different order).

We do this by sorting the arrays and passing references to the assorted versions to simple_compare. There are also some small changes to simple_compare as it should ignore the Skip hash if we are called from perm.