Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2021-09-19 06:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?