http://qs321.pair.com?node_id=209260


in reply to utf8 output with 5.8

Within "perluniintro.pod" I found this:

Note that \x.. (no {} and only two hexadecimal digits), \x{...}, and
chr(...) for arguments less than 0x100 (decimal 256) generate an
eight-bit character for backward compatibility with older Perls.  For
arguments of 0x100 or more, Unicode characters are always produced. If
you want to force the production of Unicode characters regardless of the
numeric value, use pack("U", ...) instead of \x.., \x{...}, or chr().

This explains why "\x{f6}" won't produce utf8 output.
Nonetheless the pack( "U", hex( "f6" ) ) I used originally should spit out a two byte sequence, shouldn't it?

Replies are listed 'Best First'.
Re: Re: utf8 output with 5.8
by axelrose (Scribe) on Nov 26, 2002 at 17:18 UTC
    to answer myself: it depends on the LANG environment
    [rose@localhost rose]$ export LANG=C [rose@localhost rose]$ perl -e 'print "\x{f6}"' | od -tx1 0000000 f6 0000001 [rose@localhost rose]$ perl -e 'print pack "U", 0xf6 ' | od -tx1 0000000 f6 0000001 [rose@localhost rose]$ export LANG=de_DE.UTF-8 [rose@localhost rose]$ perl -e 'print pack "U", 0xf6 ' | od -tx1 0000000 c3 b6 0000002 [rose@localhost rose]$ perl -e 'print "\x{f6}"' | od -tx1 0000000 c3 b6 0000002