admin管理员组

文章数量:1123687

I guess I went down a unicode rabbithole, and I need help getting out. I was testing how to line up things with sprintf and unicode strings, so I was kind of expecting this:

use Encode qw/decode encode/;
use utf8;

$\ = "\n"; $, = "\t";

open my $uni, "unicode_strings.txt";
my @in = map { chomp; $_ } <$uni>;

my @l = map {
    my $decoded = utf8::is_utf8($input) ? $input : decode("UTF-8", $_);
    [
     sprintf ("%-32s", $decoded),
     sprintf ("%02i", length($decoded)),
     sprintf ("%02i", length($_)),
    ]
} @in;

print encode "UTF-8", $_ for map { join " | ", $_->@* } @l;

with this input:

normal
übung
schön
fähig
niño
crème brûlée
smörgåsbord
добрый день

本文标签: perlsprintf and multicolumn Unicode charactersStack Overflow