how to output in utf-8

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I want to output text in UTF-8 without being forced to do an explicit
encoding on the text: The following thing works fine:

  use utf8;
  use Encode;

  print encode ('utf8', "München\n");

"use utf8" is necessary in order to get the non-ASCII characters into the
string at all, and the "encode" is necessary to encode the character
string into a (more or less identical) byte string. So far, so good.

Now, it is awkward to embellish every string to be output with an
"encode", so I tried the following:

  use utf8;
  use Encode;

  binmode (STDOUT, ":encode(utf8)");

  print "München\n";

However, it turns out that the "binmode" has no effect at all, and the
perl I/O insists on encoding the text using iso-8859-1. What is wrong?

Helmut Richter

Re: how to output in utf-8

On Tue, 23 Jun 2009, Helmut Richter wrote:

Quoted text here. Click to load it

Now I saw it: it must be ":encoding(utf8)" with -ing.

Sorry for asking silly questions.

Helmut Richter

Site Timeline