As for Juerd's code:
That's a Schwartzian Transform, right? (Didn't know it existed until today... :-})
However, there seems to be one problem: I get quite a few of Argument "" isn't numeric in numeric comparison (<=>) ... if any of the strings starts with a number. If I understand your code correctly, the problem lies in the : $A <=> $B part. When the string starts with a number, the split generates a first field that's defined, but empty. After replacing $A =~ /\D/ || $B =~ /\D/ with $A !~ /\d+/ || $B !~ /\d+/ (is there a better way?), it worked.
There's also a second problem, but that's partly due to my apparently incomplete requirements - I wasn't aware of that until I experimented a bit with the solutions offered here. Take the following data set:
Unsorted:x10y 1abc a10y x9y b1 abc DEF 123DEF bigboys big9boys 123DEFG 123def
Using your code or ariels' code, the result is:Sorted:1abc 123DEF 123def 123DEFG a10y abc b1 big9boys bigboys DEF x9y x10y
Whether "big9boys" should appear before "bigboys" is probably debatable - I'm not 100% sure myself wich way round would be better in my case...
I am, however, wondering about "1abc" coming before "123DEF" (and the other "123..."), though I can't see a way of changing that without breaking the other requirements. I'll have to think about it.
Thanks again,
argathin
In reply to Re: Re: Dictionary-style sort a la Tcl?
by argathin
in thread Dictionary-style sort a la Tcl?
by argathin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |