Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: Sort undef

by sundialsvc4 (Abbot)
on Jun 12, 2017 at 14:14 UTC ( #1192592=note: print w/replies, xml ) Need Help??

in reply to Sort undef

To my way of thinking, only a solution such as LanX’s cmp_undef2 ... with appropriate and generous comments ... would pass my code-review.   This is very clearly a case for a custom sort-comparison subroutine, which is prepared to handle undef as a legitimate value for $a and/or $b.   The subroutine should be a distinct sub (since it is unusual), and carefully described in comments.

Although I do not ever “down”-vote, some of these solutions are, IMHO, very clearly bad ones, the likes of which I have certainly seen in production code.   But please do not take this statement personally:   I am talking about the practice.   These attempts at solution “cabbage up a way to produce ‘the right answer,’” at least in every case (if any) that the author has tested, but they do not describe the situation, such that it can be readily shown that they will in fact work for all possible cases without relying on curiosities of the language implementation.   The accurate description of this problem is that the list can contain undefined entries, and that these should be sorted to the front of the list.   A sort-compare subroutine is the prescribed way to do this, and therefore, to my review, the only acceptable one.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1192592]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2020-08-13 21:13 GMT
Find Nodes?
    Voting Booth?
    Which rocket would you take to Mars?

    Results (75 votes). Check out past polls.