|Just another Perl shrine|
Re: New Alphabet Sort Orderby BrowserUk (Pope)
|on Apr 03, 2011 at 17:35 UTC||Need Help??|
In essence, all you need is a custom string comparison routine. And the easiest, most efficient way to do that in Perl is to use the tr/// operator to 'encode' the strings and then use the standard cmp operator.
Say your custom sort rules call for 0-4 to be sorted before alphas, and 5-9 after. And within the alphas, you want upper and lower case of any given character to be sorted together. Then you set up a mapping that maps the original strings to characters that will sort in the required order.
For the given example:
will do the trick. Now, you just transliterate your string and sort in the normal way:
Of course, you can now apply all the usual forms of sort optimisations--ST, GRT etc.--to that, but the mechanism remains the same.
The ugly head of UTF will probably complicate things a little, but, at least in the eyes of my non-UTF aware brain, it should be possible to apply the same mechanism.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.