I have a problem similar to How can I properly align UTF-8 strings with Perl's printf?:
My (Linux) system's locale default is LC_CTYPE=de_DE.UTF-8
and I wrote a Perl program (using perl-5.26.1) that is "not" using Unicode characters, but some from the ISO Latin-1 character set (that is °
for example).
There fore I did not activate any Unicode or locale features in my Perl script.
"Everything" seems to work fine with one excpetion: I'm using a printf
format of %-10s
to align strings but that does not work as expected.
Playing in the debugger I fount this behavior:
DB<1> $s='X°X'
DB<2> printf("_%3s_\n", $s)
_X°X_
Looks OK so far...
DB<3> printf("_%4s_\n", $s)
_X°X_
Oops; shouldn't that be "_ X°X_"
?
DB<4> printf("_%5s_\n", $s)
_ X°X_
Off by one?
DB<5> x length($s)
0 4
Shouldn't that be 3
?
DB<8> x ord($s[1])
0 0
DB<9> x $s
0 'X°X'
DB<10>
Shouldn't °
be encoded as one byte? I thought UTF-8 maps the Latin-1 range unmodified to Unicode.
So may questions are:
What's going on?
Is it a Perl bug?
If not, how can I fix the formatting and string length?