in reply to comparing two arrays

In addition to the direction given by the mighty crazy one, I would also point you towards serialisation methods which subsequently allow you to compare complex data structures. The most notable of serialisation modules for Perl would be Data::Dumper and Storable - The latter of which can be used to compare data with greater speed than Data::Dumper with its methods more closely tied to the C-representation of these data objects.

An example piece of comparison code using Storable might look like this:

#!/usr/bin/perl use Storable qw/freeze/; use strict; $Storable::canonical = 1; my @x = ( '1', '2', '3', '4', '5' ); my @y = ( '1', '2', '3', '4', '5' ); my @z = ( '6', '7', '8', '9', '0' ); print "x = y\n" if (freeze(\@x) eq freeze(\@y)); # True print "x = z\n" if (freeze(\@x) eq freeze(\@z)); # False print "x != z\n" if (freeze(\@x) ne freeze(\@z)); # True

Others familiar with this module will recognise the $Storable::canonical = 1 assignment as unnecessary in this example where arrays are being serialised - This assignment will allow Storable to store hashes with their elements sorted by their key, thereby allowing later comparison of the frozen serial structures.

 

Ooohhh, Rob no beer function well without!

Replies are listed 'Best First'.
Re: Re: comparing two arrays
by jdelmedi (Initiate) on Nov 24, 2001 at 19:44 UTC
    Thank you very much for your input!! It has helped me to understand a little better.