我有一个以下 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
理由是我希望空格字符排在其他字母之前。有没有办法让我的 Collator 对象帮助我做到这一点?