Perl 有没有办法使printf/sprintf句柄正确组合字符?

Perl 有没有办法使printf/sprintf句柄正确组合字符?,perl,unicode,printf,Perl,Unicode,Printf,在printf和sprintf的计算中,组合字符似乎算作整个字符: [ é] [ é] 上面的文本由以下代码创建: #!/usr/bin/perl use strict; use warnings; binmode STDOUT, ":utf8"; for my $s ("\x{e9}", "e\x{301}") { printf "[%5s]\n", $s; } 我希望代码能够打印: [ é] [ é] 在函数描述中,我没有看到任何关于U

printf
sprintf
的计算中,组合字符似乎算作整个字符:

[    é]
[   é]
上面的文本由以下代码创建:

#!/usr/bin/perl

use strict;
use warnings;

binmode STDOUT, ":utf8";

for my $s ("\x{e9}", "e\x{301}") {
        printf "[%5s]\n", $s; 
}
我希望代码能够打印:

[    é]
[    é]

在函数描述中,我没有看到任何关于Unicode的讨论,更不用说组合字符了。
printf
sprintf
在Unicode面前毫无用处吗?这只是Perl 5.20.1中可以修复的一个bug吗?有人写过替代品吗?

答案似乎是使用


你可能应该意识到这一点。特别是,它处理的正是这个问题。作为奖励,PerlV5.20.2将其作为
perldocunicok
提供

在任何情况下:该条款中包含的代码如下:

use Unicode::GCString;
use Unicode::Normalize;

my @words = qw/crème brûlée/;
@words    = map { NFC($_), NFD($_) } @words;

for my $str (@words) {
    my $gcs  = Unicode::GCString->new($str);
    my $cols = $gcs->columns;
    my $pad  = " " x (10 - $cols);
    say str, $pad, " |";
}
use Unicode::GCString;
use Unicode::Normalize;

my @words = qw/crème brûlée/;
@words    = map { NFC($_), NFD($_) } @words;

for my $str (@words) {
    my $gcs  = Unicode::GCString->new($str);
    my $cols = $gcs->columns;
    my $pad  = " " x (10 - $cols);
    say str, $pad, " |";
}