Update1:
Come back with some code (only breifly tested):
$a = [[[1,2],[2,3]], [[3,4],[4,5]], [[4,5],[5,6]]];
$b = [[[1,2],[2,3]], [[3,4],[4,5]], [[4,5],[5,6]]];
print is_array_equal($a, $b);
sub is_array_equal {
my ($array1, $array2) = @_;
if ($#array1 != $#array2) {
return 0;
} else {
print "here\n";
for (my $i = 0; $i <= $#{$array1}; $i ++) {
print "there\n";
if ((ref($array1->[$i]) eq "ARRAY") && (ref($array2->[$i])
+ eq "ARRAY")) {
if (!is_array_equal($array1->[$i], $array2->[$i])) {
return 0;
}
} elsif (!ref($array1->[$i]) && !ref($array2->[$i])) {
print "compare $array1->[$i] and $array2->[$i]\n";
if ($array1->[$i] != $array2->[$i]) {
return 0;
}
} else {
return 0;
}
}
}
return 1;
}
Original:
Looks like you are comparing three dimentional arrays.
What you can do is to write a function that calls itself recursively:
- First it compares number of elements, if not equal, then the two arrays are not equal, so return false;
- If number of elements are the same, then iterate thru all elements, for each pair:
- If both elements are atomic, simply compare their values
- If one is atomic , one is collection, no need to continue, return false
- If both are collection, call this func recursively)
This would not only work for your three dimentional array, but array at any depth.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.