Re: not wanting to delete somebody's home directory
> You sometimes will end up with a sort that like this:
> 1 11 12 ... 19 2 21 ... 3
> I'm sort of hoping the reason is easy to spot, as I am fighting a headache
Would the following sequence (and the image of a stern looking librarian)
be more intuitive ?
A AA AB ... AI B BA ... C
Where in this card index box would you insert "D" or "AAAAA" ?
A human would notice if a set of sorting subjects consists entirely
of numbers and then use a numeric sorting criterion.
But the default criterion with the mentioned Perl code is obviously lexical.
The decision between "19" and "2" is made like this:
The single character '1' has a lower sort rank than '2'. So the decision is
made and the '9' is of no importance. "19" comes before "2".
"11" is lower than "12" because the first characters are equal, and
the second character '1' is lower than the second character '2'.
"1" is lower than "11" because there is no second '1' in "1".
Who quits early has the lower rank.
The classic method to make both sorting criteria match is to prepend
'0' characters to the shorter numbers so that all number texts have the
Then lexical ordering yields
01 02 03 11 12 ... 19 21
If you want to intensify your headache, see the mathematical constraints
for a usable sorting criterion at
Beginning at example line 23 of
you can easily cause great sorting confusion by a self-made non-usable
criterion. The rules of rock-paper-scissors are a good start.
Have a nice day :)