Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: New Alphabet Sort Order

by Polyglot (Chaplain)
on Apr 03, 2011 at 23:44 UTC ( [id://897257]=note: print w/replies, xml ) Need Help??


in reply to Re: New Alphabet Sort Order
in thread New Alphabet Sort Order

Khen, thank you for the tip. I took a look at that and asked up the line about it. I guess many people in Laos still use that font system. However, for this project, we are intending to use unicode. Unicode still seems a bit new to Lao, so it will not be without some difficulties. But we feel it may be the best and most future-compatible standard to follow.

Blessings,

~Polyglot~

Replies are listed 'Best First'.
Re^3: New Alphabet Sort Order
by furry_marmot (Pilgrim) on Apr 04, 2011 at 22:55 UTC

    Polyglot,

    I think BrowserUK's solution is the direction you'll end up going. The ST and GRT he referred to are the Schwartzian Transform and Guttman Rosler Transform, respectively. You only need the first.

    The link explains it, but basically you transform a list of things you want to sort into a list of two-element arrays. The first element is the key, set up so you can easily sort it. The second is the original element, untouched. You can do it in separate steps, but the transform is more efficient if you have a lot of elements. The key thing you need is a function that can create a function that will create a key that you can sort on.

    Here's an example, sorting movie names, done separately first.
    use Lingua::EN::Numbers qw(num2en); sub make_key { $_ = shift; s/^(?:The|An|A) // || s/^[^A-Z_]+(\d+)/num2en; return $_; } my @movies = ( '(500) Days of Summer', # F for Five hundred 'The Music Man', # M for Music 'The Good, the Bad, and the Ugly' # G for Good ); my @tmp = (); for (@movies) { push @tmp [ make_key($_), $_ ] # 2-element anonymous array } @tmp = sort { $a->[0] cmp $b->[0] } @tmp; # sort on first elements @movies = map { $_->[1] } @tmp; # pull off second element from ea +ch # anonymous array print "$_\n" for @movies; __END__ Prints: (500) Days of Summer The Good, the Bad, and the Ugly The Music Man
    Now, MUCH less complicated:
    use Lingua::EN::Numbers qw(num2en); sub make_key { $_ = shift; s/^(?:The|An|A) // || s/^[^A-Z_]+(\d+)/num2en; return $_; } my @movies = ( '(500) Days of Summer', # F for Five hundred 'The Music Man', # M for Music 'The Good, the Bad, and the Ugly' # G for Good ); # Here's the transform. Read from the bottom up. my @movies = # original elements replaced with same +, but sorted map { $_->[1] } # pull off second element from each sort { $a->[0] cmp $b->[0] } # sort arrays on first elements map { [ make_key($_), $_ ] } # 2-element anonymous array becomes ne +w $_ @movies; print "$_\n" for @movies; __END__ Prints: (500) Days of Summer The Good, the Bad, and the Ugly The Music Man
    Good luck!

    --marmot

    UPDATE: Corrected a typo bug in the ST that came from copying the first version.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://897257]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2024-04-19 08:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found