1

我有一个以下 Perl 脚本,它对单词列表进行排序,使用 utf-8 编码:

use HTML::Entities;
use Unicode::Collate::Locale;
use utf8;

my @array = (
     "Another", 
     "An Other", 
     "Anóther", 
     "An Óther", 
     "Anòther", 
     "An Òther", 
     "Anôther", 
     "An Ôther", 
     "Anöther", 
     "An Öther", 
     "Anõther", 
     "An Õther"
     );

my $lang = "da";

printf ("Lang code is: %s\n", $lang);

my $coll = Unicode::Collate::Locale->new(locale => "$lang");

my @result = $coll->sort(@array);


foreach my $item (@result){

print $item, "\n";
}

这是它的输出:

Lang code is: da
An Other
Another
An Óther
Anóther
An Òther
Anòther
An Ôther
Anôther
An Õther
Anõther
An Öther
Anöther

但是,我希望它输出:

An Other
An Óther
An Òther
An Ôther
An Õther
An Öther
Another
Anóther
Anòther
Anôther
Anõther
Anöther

理由是我希望空格字符排在其他字母之前。有没有办法让我的 Collat​​or 对象帮助我做到这一点?

4

1 回答 1

3

尝试将变量权重设置为'non-ignorable'

my $coll = Unicode::Collate::Locale->new(
    locale   => $lang,
    variable => 'non-ignorable',
);

有关详细信息,请参阅Unicode 排序算法 (UCA) 规范中的变量加权部分。

于 2013-02-27T21:35:45.487 回答