in reply to Re^2: Encoding changed from Greek to somethign else
in thread Encoding changed from Greek to somethign else

You have webspace. Just upload your index.pl again under a different name, for instance problem.txt, then post the link. Make sure the file is really downloadable and not unintentionally executed by the webserver.

Alternatively, paste your code here to perlmonks, and wrap it into <readmore><code> ... </code></readmore>.

I prefer the first method here, because that way we get to examine encoding problems better.

覧覧覧覧覧覧覧覧覧覧

I explain the stuff about XHTML, but first a bit of theory. Perl strings only have characters.

my $greeting = 'ευπρόσδεκτος';

You are going to send those strings over the Web to the client browser. But characters do not exist out of Perl, only bytes. Bytes will travel down through the networks. So you have to convert characters into bytes, this is called encoding. I choose the encoding UTF-8 because it is best.

use Encode; print encode('UTF-8', $greeting);

If we would hexdump the resulting bytes, it would look like this: ce b5 cf 85 cf 80 cf 81 cf 8c cf 83 ce b4 ce b5 ce ba cf 84 ce bf cf 82

That is the short version. Does that make sense to you? If not, read perlunitut and perlunifaq.

覧覧覧覧覧覧覧覧覧覧

In a CGI environment, you are printing everything to STDOUT, and putting encode() everywhere gets pretty tiresome. That is why I binmoded STDOUT, so the encoding applies to it globally. Then a simple print suffices, like before.

The rest is just a consequence of using UTF-8. When you send out any kind of text (XHTML counts as text here, too), you have to announce the encoding to the browser. That's part of HTTP. This is why there is a Content-Type header with some charset= at the end.

Similar thing goes for XHTML (and all XML generally), it also needs to declare in which encoding it is written. This is why there is an encoding attribute between the <?xml ... ?> bits.

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.