in reply to And lexicographically means...
in thread Inconsistent column Schwartzian Transform attempt

If you need keys sorted in a different order, just sprintf them differently. For descending numeric keys, sprintf 9999999-$fld. For descending string keys... Hmmm, don't have an easy answer to that one.

# Ascending sort { $a cmp $b } LIST sort { $a <=> $b } LIST # Descending sort { $b cmp $a } LIST sort { $b <=> $a } LIST
I think using 9999999-$foo is an ugly way to do a descending sort, and I think sprintfing to sort numbers using cmp is evil, because there's already the <=> operator and you can use every routine you want for sorting - just reverse it if you want a descending sort.

U28geW91IGNhbiBhbGwgcm90MTMgY
W5kIHBhY2soKS4gQnV0IGRvIHlvdS
ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
geW91IHNlZSBpdD8gIC0tIEp1ZXJk

Replies are listed 'Best First'.
It's an efficiency thing, not an elegance thing
by RMGir (Prior) on Mar 16, 2002 at 19:41 UTC
    I'm building up the string key using sprintf just to avoid perl code in the comparison function.

    Evil yes. But also EFFICIENT.

    I'll bet for a long sort, it's probably faster to do a cmp than several cmps and <=>.

    But it's the weekend; I'm too lazy to fire up Benchmark. :)
    --
    Mike