http://qs321.pair.com?node_id=1192615


in reply to Re: Sort undef
in thread Sort undef

This being a simple case, I thought the typical way to do it would be in the form:

sort { (defined($a) <=> defined($b)) || ($a cmp $b) }

Replies are listed 'Best First'.
Re^3: Sort undef
by LanX (Sage) on Jun 12, 2017 at 16:29 UTC
    Nice! I was worried that <=> can't handle "" without warnings, but that's not the case here. :)

    (empty string is the false value returned from defined(undef) )

    EDIT

    Forget it, I'm getting old ... false is a dual var which resolves to 0 in numeric context.

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!