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


in reply to utf8 output with 5.8

In 5.8 you can (and should) specify which encoding perl should use when writing.
By default perl5.8 will assume you want latin1 output (but warn and then output in utf8 those strings that do not fit in latin1).

If you switch your environment to utf8 with something like

env LC_CTYPE=en_US.UTF-8 perl -e ...
then you should get the output you expected.

A different way to do it (TIMTOWTDI) is to explicitly switch STDOUT to a different encoding using the newly repurposed binmode():

binmode STDOUT, ':utf8';

A third way is using the new use open pragma:

use open ':utf8', ':std';

So to get your one-liner to work, it becomes:

perl -Mopen=:utf8,:std -e '$c="f6"; $u=pack("U",hex($c)); print $u, "\ +x{f6}"' | od -tx1

I'm sure you'll be able to find your way to the documentation for these new perl5.8 features. A good start is the perluniintro manpage.

Replies are listed 'Best First'.
Re: Re: utf8 output with 5.8
by axelrose (Scribe) on Oct 30, 2002 at 10:10 UTC
    Thanks for your good explanation!
    I'm developing mainly under MacPerl and need to ask others to check 5.8.

    One question still:
    How can I use those new options in a compatible way so 5.6 scripts don't choke?