Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: New Alphabet Sort Order

by Khen1950fx (Canon)
on Apr 03, 2011 at 17:27 UTC ( #897222=note: print w/ replies, xml ) Need Help??


in reply to New Alphabet Sort Order

Alo might prove to be useful for you. I'd give it a ++.


Comment on Re: New Alphabet Sort Order
Re^2: New Alphabet Sort Order
by Polyglot (Monk) on Apr 03, 2011 at 23:44 UTC
    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~

      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
Node Status?
node history
Node Type: note [id://897222]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2014-07-26 08:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls