in reply to Compare two arrays
You want to compare each element of @a against the element of the same index in @b, right? This will do it.
print "Index: $_ => \@a: $a[$_], \@b: $b[$_]\n" for grep { $a[$_] != $b[$_] } 0 .. $#a;
...or...
foreach( 0 .. $#a ) { print "Index: $_ => \@a: $a[$_], \@b: $b[$_]\n" if $a[$_] != $b[$_ +]; }
Which you choose kind of depends on whether you're more interested in keeping a list of indices to the dissimilar elements, or simply interested in processing the mismatches one by one. The grep version is handy for getting the list of mismatches.
Dave
|
|---|