就在我认为我理解Perl中的多语种整理时......
我得到了$和%的相对排序看起来不同的结果 当我使用Unicode排序规则时,与使用普通旧的" cmp"相比。我不认为我的 Unicode结果是正确的。
以下脚本输出:
Vanilla collation: alpha CMP beta for is -1 # I get it: "alpha" comes before "beta"
Unicode::Collate collation: alpha CMP beta is -1 # I get it: "alpha" comes before "beta"
Vanilla collation: $ CMP % for is -1 # I get it $ comes before %
Unicode::Collate collation: $ CMP % is 1 # So why is this result different?
use HTML::Entities;
use Unicode::Collate::Locale;
require 'Unicode/Collate/Locale/fr.pl';
my $COLL = Unicode::Collate::Locale->new(
locale => "fr",
);
{
my $a_text = "alpha";
my $b_text = "beta";
my $result = $a_text cmp $b_text; # returns 1, 0, or -1.
printf qq(Vanilla collation: %s CMP %s for $lang is %s\n), $a_text, $b_text, $result;
my $result1 = $COLL->cmp( $a_text, $b_text ); # returns 1, 0, or -1.
printf qq(Unicode::Collate collation: %s CMP %s is %s\n), $a_text, $b_text, $result1;
}
{
my $a_text = "\$";
my $b_text = "%";
my $result = $a_text cmp $b_text; # returns 1, 0, or -1.
printf qq(Vanilla collation: %s CMP %s for $lang is %s\n), $a_text, $b_text, $result;
my $result1 = $COLL->cmp( $a_text, $b_text ); # returns 1, 0, or -1.
printf qq(Unicode::Collate collation: %s CMP %s is %s\n), $a_text, $b_text, $result1;
}
答案 0 :(得分:2)
结果是正确的。
Unicode Collation Algorithm在mappings的帮助下定义了事物的排序方式,其中包括以下内容:
0024 ; [.15BA.0020.0002] # DOLLAR SIGN
0025 ; [*037A.0020.0002] # PERCENT SIGN