I have a program that takes input from a utf-8 text file which contains text in 10 languages. The data is treated variously, but the bit posing a problem is a "simple" alphabetical sort, language by language. English works fine, no surprise. However, in French the É is placed after Z whereas it should be after E; and I won't even go into what it does with Greek ;)
Here's a snippet:
use strict;
use warnings;
use diagnostics;
use utf8;
use open ':utf8';
use FileHandle;
# lots of treatment in between .... then
foreach $term_name (sort keys %term) {
if ( defined $term{$term_name}{$LL}{term} ) {
$text = $term{$term_name}{$LL}{term};
$char_1 = uc(substr($text,0,1));
push @char, $char_1;
}
}
remove_duplicates(@char);
@char = sort(@char);
where $LL is the language code, and term is the term in that language. The subroutine remove_duplicates() just gets rid of excess letters so that @char contains only unique letters.
I'm using Perl ActiveState 5.8.0 on Windows NT4. I've read the docs on unicode and utf-8; unfortunately they all seem to imply that sort() works as is.
I'm looking either to sort in true alphabet fashion where É follows E, or to combining anything commencing with an accented character into the non-accented character. Any tips would be appreciated.
Thank you
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.