http://www.perlmonks.org?node_id=851703


in reply to Unexpected Output

For checking the length of an array,don't use $#arrayname because it won't give the number of elements in an array and it gives the highest index of the array which is number of elements - 1 in the array.If you want to check the length of an array, you assign an array to scalar, then it will give the actual number of elements in the array.There is one more problem in $#arrayname, it gives the value by adding the value of $[ with highest index of an array.In your script, if you change the value of $[ variable, then $#arrayname won't give the correct value.