in reply to comparing two arrays
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 |