rsriram has asked for the wisdom of the Perl Monks concerning the following question:
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Comparing arrays with text contents
by Zaxo (Archbishop) on Jun 21, 2006 at 10:53 UTC | |
Re: Comparing arrays with text contents
by Samy_rio (Vicar) on Jun 21, 2006 at 11:00 UTC | |
Re: Comparing arrays with text contents
by mickeyn (Priest) on Jun 21, 2006 at 10:55 UTC | |
Re: Comparing arrays with text contents
by prasadbabu (Prior) on Jun 21, 2006 at 10:56 UTC | |
Re: Comparing arrays with text contents
by Moron (Curate) on Jun 21, 2006 at 11:38 UTC |