我有一个以下的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
理由是我希望SPACE角色在其他字母之前排序。有没有办法让我的Collator对象帮助我做到这一点?
答案 0 :(得分:3)
尝试将变量权重设置为'non-ignorable'
:
my $coll = Unicode::Collate::Locale->new(
locale => $lang,
variable => 'non-ignorable',
);
有关详细信息,请参阅Unicode归类算法(UCA)规范中的Variable Weighting部分。