I need to compare two arrays:
@anc=("BX1.01.001","BX1.01.002","BX1.01.003","BX1.01.004","BX1.01.005" +,"BX1.01.006"); @ind=("BX1.01.002","BX1.01.002","BX1.01.003","BX1.01.004","BX1.01.005" +,"BX1.01.006");
My function to compare these two array's is
sub comp_arr { @arr1=sort($_[0]); @arr2=sort($_[1]); # To check if the number of elements in both arrays match if ($#arr1 != $#arr2) { print "Indicator and anchor count do not match"; exit; } #Actual compare starts here for ($x=0; $x <= $#arr2; $x++) { if ($arr2[$x] ne $arr1[$x]) { print ("Anchor/indicator mismatch in $arr1[$x]\n"); } }
Even if the arrays are similar or if there are any differences, I get an error message stating there is a mismatch in the first element. Can someone help me out by telling me what's wrong in the above codes?
Sriram
proper code tags by holli
In reply to Comparing arrays with text contents by rsriram
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |