Download Shareware and Freeware Software for Windows, Linux, Macintosh, PDA

line Home  |  About Us  |  Link To Us  |  FAQ  |  Contact

Serving Software Downloads in 956 Categories, Downloaded 50.241.089 Times

Array::Compare 1.14

  Date Added: September 19, 2010  |  Visits: 1.363

Array::Compare

Report Broken Link
Printer Friendly Version


Product Homepage
Download (92 downloads)



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..

Requirements: No special requirements
Platforms: Linux
Keyword: Arraycompare Arrays Compare Comparison Deffull Libraries Programming Skip Whitespace
Users rating: 0/10

License: Freeware Size: 8.19 KB
USER REVIEWS
More Reviews or Write Review


ARRAY::COMPARE RELATED
Libraries  -  List::Compare 0.33
List::Compare is a Perl module to compare elements of two or more lists. SYNOPSIS The bare essentials: @Llist = qw(abel abel baker camera delta edward fargo golfer); @Rlist = qw(baker camera delta delta edward fargo golfer hilton); $lc =...
184.32 KB  
Libraries  -  Judy 1.0.1
Judy is a C library that provides a state-of-the-art core technology that implements a sparse dynamic array. Judy arrays are declared simply with a null pointer. A Judy array consumes memory only when it is populated, yet can grow to take...
1024 KB  
Libraries  -  Bio::SAGE::Comparison 1.00
Bio::SAGE::Comparison module compares data from serial analysis of gene expression (SAGE) libraries. SYNOPSIS use Bio::SAGE::Comparison; $sage = Bio::SAGE::Comparison->new(); This module provides several tools for comparing data generated...
8.19 KB  
Libraries  -  Struct::Compare 1.0.1
Struct::Compare is a recursive diff for perl structures. SYNOPSIS use Struct::Compare; my $is_different = compare($ref1, $ref2); Compares two values of any type and structure and returns true if they are the same. It does a deep comparison...
3.07 KB  
Multimedia & Graphics  -  Image Compare 2 1.1
The Image Compare 2 tool manages to find duplicate images, that can be deleted with a single mouse click. It uses a unique algorithm to detect if an image is identical or similar, even when it is scaled or rotated. Image Compare 2 now comes with...
 
Libraries  -  DAEMon Raco Libraries 0.3
DAEMon Raco Libraries (DRLibs) is a collection of useful functions, objects, and routines for C++. Whats New in This Release: - This release adds new libraries to manage object lists: doublelist.dr.h, simplelist.dr.h, and sortedlist.dr.h..
28.67 KB  
Libraries  -  Test::Number::Delta 1.03
Test::Number::Delta is a Perl module to compare the difference between numbers against a given tolerance. SYNOPSIS # Import test functions use Test::Number::Delta; # Equality test with default tolerance delta_ok( 1e-5, 2e-5, values within...
18.43 KB  
Libraries  -  Adobe Source Libraries 1.0.29
The Adobe Source Libraries (ASL) are a collection of C++ libraries building foundation technology to allow the construction of commercial applications by assembling generic algorithms through declarative descriptions. Whats New in This Release:...
8.2 MB  
Libraries  -  Ham Radio Control Libraries 1.2.6.2
Ham Radio Control Libraries is a development effort to provide a consistent interface for programmers wanting to incorporate radio control in their programs. Hamlib is not a complete user application, rather, it is a software layer intended to...
1.4 MB  
Libraries  -  PoJoe Component Libraries 1.1
PoJoe Component Libraries project is a set of Java POJO components, originally developed for OSMQ. Developers have found these components useful in building robust enterprise applications. Of note are: a FIFO queue that utilizes memory until a...
890.88 KB  
NEW DOWNLOADS IN PROGRAMMING, LIBRARIES
Programming  -  Cedalion for Linux 0.2.6
Cedalion is a programming language that allows its users to add new abstractions and define (and use) internal DSLs. Its innovation is in the fact that it uses projectional editing to allow the new abstractions to have no syntactic limitations.
471.04 KB  
Programming  -  Math::GMPf 0.29
Math::GMPf - perl interface to the GMP library's floating point (mpf) functions.
30.72 KB  
Programming  -  Net::Wire10 1.08
Net::Wire10 is a Pure Perl connector that talks to Sphinx, MySQL and Drizzle servers. Net::Wire10 implements the low-level network protocol, alias the MySQL wire protocol version 10, necessary for talking to one of the aforementioned...
30.72 KB  
Programming  -  logilab-common 0.56.2
a bunch of modules providing low level functionnalities shared among some python projects devel Please note that some of the modules have some extra dependencies. For instance, logilab.common.db will require a db-api 2.0 compliant...
174.08 KB  
Programming  -  OpenSSL for linux 1.0.0a
The OpenSSL Project is a collaborative effort to develop a robust, commercial-grade, full-featured, and Open Source toolkit implementing the Secure Sockets Layer (SSL v2/v3) and Transport Layer Security (TLS v1) protocols as well as a...
3.83 MB  
Libraries  -  wolfSSL 4.0.0
The wolfSSL embedded SSL/TLS library is a lightweight SSL library written in ANSI standard C and targeted for embedded and RTOS environments - primarily because of its small size, speed, and feature set. It is commonly used in standard operating...
3.88 MB  
Libraries  -  EuGTK 4.8.9
Makes it easy to develop good- looking, fast, cross-platform programs that run on Linux, OS X, and Windows. Euphoria is a very fast interpreted/compiled language with straight-forward syntax. EuGTK allows programming in a clean, object-oriented...
10.68 MB  
Libraries  -  Linux User Group Library Manager 1.0
The LUG Library Manager is a project to help Linux User Groups start their own library. A LUG library is helpful to the community at large because it increases access to information, and gives everyone the opportunity to become more knowledgeable.
5.35 KB  
Libraries  -  Module::MakefilePL::Parse 0.12
Module::MakefilePL::Parse is a Perl module to parse required modules from Makefile.PL. SYNOPSIS use Module::MakefilePL::Parse; open $fh, Makefile.PL; $parser = Module::MakefilePL::Parse->new( join("", ) ); $info = $parser->required;...
8.19 KB  
Libraries  -  sqlpp 0.06
sqlpp Perl package is a SQL preprocessor. sqlpp is a conventional cpp-alike preprocessor taught to understand SQL ( PgSQL, in particular) syntax specificities. In addition to the standard #define/#ifdef/#else/#endif cohort, provides also...
10.24 KB