Main > Programming > Libraries >

Array::Compare 1.14

Array::Compare 1.14

Sponsored Links

Array::Compare 1.14 Ranking & Summary

RankingClick at the star to rank
Ranking Level
User Review: 0 (0 times)
File size: 0.008 MB
Platform: Any Platform
License: Perl Artistic License
Price:
Downloads: 800
Date added: 2007-08-15
Publisher: Dave Cross

Array::Compare 1.14 description



SYNOPSIS

use Array::Compare;

my $comp1 = Array::Compare->new;
$comp->Sep(|);
$comp->Skip({3 => 1, 4 => 1});
$comp->WhiteSpace(0);
$comp->Case(1);

my $comp2 = Array::Compare->new(Sep => |,
WhiteSpace => 0,
Case => 1,
Skip => {3 => 1, 4 => 1});

my @arr1 = 0 .. 10;
my @arr2 = 0 .. 10;

$comp1->compare(@arr1, @arr2);
$comp2->compare(@arr1, @arr2);

If you have two arrays and you want to know if they are the same or different, then Array::Compare will be useful to you.
All comparisons are carried out via a comparator object. In the simplest usage, you can create and use a comparator object like this:

my @arr1 = 0 .. 10;
my @arr2 = 0 .. 10;

my $comp = Array::Compare->new;

if ($comp->compare(@arr1, @arr2)) {
print "Arrays are the samen";
} else {
print "Arrays are differentn";
}

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 seperator for an existing comparator object

$comp->Sep(|);

In general you should choose a separator character that wont 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 theyre 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 comparision 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.

my $comp = Array::Compare->new(DefFull => 1);
$comp->compare(@arr1, @arr2); # Full comparison

$comp->DefFull(0);
$comp->compare(@arr1, @arr2); # Simple comparison

$comp->DefFull(1);
$comp->compare(@arr1, @arr2); # Full comparison again

Secondly, you can access the full comparison method directly

$comp->full_compare(@arr1, @arr2);

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:

my %skip = (2 => 1, 4 => 1);
my @a = (0, 1, 2, 3, 4, 5);
my @b = (0, 1, X, 3, X, 5);

my $comp = Array::Compare->new(Skip => %skip);

$comp->compare(@a, @b);

This should return true, as we are explicitly ignoring the columns which differ.

Of course, having created a comparator object with no skip hash, it is possible to add one later:

$comp->Skip({1 => 1, 2 => 1});

or:

my %skip = (1 => 1, 2 => 2);
$comp->Skip(%skip);

To reset the comparator so that no longer skips elements, set the skip hash to an empty hash.

$comp->Skip({});

You can also check to see if one array is a permutation of another, i.e. they contain the same elements but in a different order.

if ($comp->perm(@a, @b) {
print "Arrays are permsn";
else {
print "Nope. Arrays are completely differentn";
}

In this case the values of WhiteSpace and Case are still used, but Skip is ignored for, hopefully, obvious reasons.

Array::Compare 1.14 Screenshot

Advertisements

Array::Compare 1.14 Keywords

Bookmark Array::Compare 1.14

Hyperlink code:
Link for forum:

Array::Compare 1.14 Copyright

WareSeeker periodically updates pricing and software information of Array::Compare 1.14 full version from the publisher, so some information may be slightly out-of-date. You should confirm all information before relying on it. Software piracy is theft, Using crack, password, serial numbers, registration codes, key generators is illegal and prevent future development of Array::Compare 1.14 Edition. Download links are directly from our publisher sites, torrent files or links from rapidshare.com, yousendit.com or megaupload.com are not allowed

Allok Video Splitter 2.2.0 Review:

Name (Required)
Email(Required)
Captcha
Featured Software

Want to place your software product here?
Please contact us for consideration.

Contact WareSeeker.com
Related Software
Struct::Compare is a recursive diff for perl structures. Free Download
AT Media Page provides a simple and easy to use Plone Page which can contain ATImages. Free Download
Set::Array Perl module contains arrays as objects with lots of handy methods and support for method chaining. Free Download
Array Designer helps design thousands of efficient, highly specific oligos to make microarrays for SNP genotyping. Free Download
CMMS is an easy to use tool for managing and maintaining business equipment. Free Download
AVL Array is an STL-like container for C++ that fills the gap between vector. Free Download
Tie::Array::PackedC is a Tie a Perl array to a C-style array (packed; elements of a single, simple data type). Free Download
Debt Payment Comparison Calculator is a free, flexible tool for your Web site that does more than just calculate monthly payment Free Download