In the OP's code. The return $a lines will return values like 'etc'. Sort expects -1, 0 or 1 as is returned by cmp and <=>.
Premature optimization is the root of all job security
| [reply] [d/l] |
GrandFather did a better job of explaining it than I did.
sort expects the comparator subroutine to return a value less than zero, equal to zero, or greater than zero for the conditions of left < right, left == right, and left > right. So the use of cmp and <=> is commonplace. But some of the possible return values of the OP's comparator are strings, which will probably not be of much use to sort. It seems as though the OP thinks he should return the value that has higher precedence in the comparison, which is a fallacy, and except for unusual circumstances, indicative of a bug in the code.
| [reply] [d/l] [select] |
Yeah, it's been probably more than five years since I had to write my own sort routine and faulty memory did me in. It doesn't help that all but three of the sites in my actual data have numbers in them and most are all numbers, so it appeared to be working. Thanks for the help!!
| [reply] |
In the end, your intuition was correct (don't ignore the warnings unless you know why they're happening), and the warnings served their purpose (alerted you to a potential bug). They may not have explicitly come out and said what was wrong with the code, but they did point to the region of code where the Perl runtime was sensing a possible problem, and with a little digging you presumably have been able to fix the issue..
| [reply] |