in reply to Why didn't this sort?

A guess (since you didn't include much code) - foreach is creating a sorted list of members of your array, not actually sorting your array. An example:

@array=(2, 3, 1, 0); foreach (sort @array){ print "$_ - "; } print "\n"; print join " - ", @array; print "\n"; @array = sort @array; print join " - ", @array; __END__ Output: 0 - 1 - 2 - 3 - (printed in loop) 2 - 3 - 1 - 0 (after loop, still unsorted) 0 - 1 - 2 - 3 (after sorting, now sorted)

Notice @a prints as if it is sorted in the loop, but after the loop it is still unsorted. If you want the array sorted, @array = sort @array; will work.