in reply to Re: Argument isn't numeric in sort -- resolve or ignore?
in thread Argument isn't numeric in sort -- resolve or ignore?

A bug where, sir? In perl, or in the OPs code? I'm legitimately interested in any details/feedback you can provide.
  • Comment on Re^2: Argument isn't numeric in sort -- resolve or ignore?

Replies are listed 'Best First'.
Re^3: Argument isn't numeric in sort -- resolve or ignore?
by GrandFather (Saint) on Feb 26, 2016 at 01:56 UTC

    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
Re^3: Argument isn't numeric in sort -- resolve or ignore?
by davido (Cardinal) on Feb 26, 2016 at 06:27 UTC

    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.


    Dave

      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!!

      Elda Taluta; Sarks Sark; Ark Arks
      My deviantART gallery

        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..


        Dave