kalyanrajsista has asked for the wisdom of the Perl Monks concerning the following question:
Hello all,
I'm trying to compare two hashes and arrays. I didn't find any problem when comparing with hashes where in keys are in whatever order.
I accept that my understanding is wrong and certainly it should not match. But still want to match the arrays where data is same in both array's but order varies
use strict; use Data::Compare; my $h1 = { 'recid2' => '345', 'recid1' => '123' }; my $h2 = { 'recid1' => '123', 'recid2' => '345' }; my @a1 = (1,2,3); my @a2 = (3,2,1); # simple procedural interface print 'structures of $h1 and $h2 are ', Compare($h1, $h2) ? "" : "not ", "identical.\n"; # simple procedural interface print 'structures of $a1 and $a2 are ', Compare(\@a1, \@a2) ? "" : "not ", "identical.\n";
Any suggestions please
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Compare Hashes and Arrays
by BioLion (Curate) on Dec 16, 2009 at 13:25 UTC | |
|
Re: Compare Hashes and Arrays
by Ratazong (Monsignor) on Dec 16, 2009 at 12:21 UTC | |
|
Re: Compare Hashes and Arrays
by Skeeve (Parson) on Dec 16, 2009 at 13:08 UTC |