Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Sorting Vietnamese text

by Atacama (Sexton)
on Dec 22, 2013 at 18:48 UTC ( #1068107=note: print w/replies, xml ) Need Help??

in reply to Sorting Vietnamese text

Given the file is large, you can try using Sort::External supplied with the following sortsub: sub { $index{$Sort::External::a} <=> $index{$Sort::External::b} } Where %index is a hash with letters from the vietnamese alphabet as its keys and their corresponding positions in the alphabet as its values.

Replies are listed 'Best First'.
Re^2: Sorting Vietnamese text
by pdenisowski (Acolyte) on Dec 22, 2013 at 20:09 UTC
    Thanks - could you post a small code example? I've not quite sure how to create and reference the index.
      moritz basically implemented a similar idea (that I formulated incorrectly in my message, btw). I think it will be better to use the unicode collation module advised above.
      #!/usr/bin/env perl use warnings; use strict; use Sort::External; use Unicode::Collate::Locale; my $in = shift // 'large-unsorted.txt'; my $out = shift // 'sorted.txt'; my $comparator = Unicode::Collate::Locale->new(locale =>'vi'); my $sorter = Sort::External->new ( sortsub => sub { $comparator->cmp($Sort::External::a, $Sort::Externa +l::b) } ); open my $unsorted, '<', $in or die $!; $sorter->feed($_) while <$unsorted>; $sorter->finish(outfile => $out);

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1068107]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (13)
As of 2017-02-23 19:04 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (350 votes). Check out past polls.