in reply to confusing number of elements in an array

I think there are two problems with your code. The more serious one is that you initialize the $index variable to zero after you increment it by calling sorter. Thus, $index will be zero by the time you print the array. The lesser problem is an off-by-one error in the for loop: the halting condition should be $i < $index, as $index points after the last element of the array.