Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: utf8 output with 5.8

by Arrowhead (Monk)
on Oct 29, 2002 at 20:55 UTC ( #208871=note: print w/replies, xml ) Need Help??

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?

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://208871]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2023-03-27 23:26 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (66 votes). Check out past polls.