Best way to output literal strings as UTF-8 ?

Y

Yohan N. Leder

Using Perl 5.8.8, I'm trying to found the best way to support UTF-8
everywhere about outputted literal strings (from source code) toward
generated UTF-8 HTML in browser.

I've done this :
- Saved source code (containing the literal strings) as UTF-8
- Added a "use utf8;" line in code
- Added a "binmode(STDOUT, ":utf8");" line in code

And accentuated character doesn't appear well. If I save source code as
ISO-8859-1, all sounds right. So, I'm wondering if they didn't been UTF-
8 encoded twice.

What the best combination ? Do I have to remove the binmode line,
knowing source code is already in UTF-8 ? Does the use utf8 unuseful ?
Is it best to not save source as UTF-8 ? What ?
 
Y

Yohan N. Leder

Using Perl 5.8.8, I'm trying to found the best way to support UTF-8
everywhere about outputted literal strings (from source code) toward
generated UTF-8 HTML in browser.

I've done this :
- Saved source code (containing the literal strings) as UTF-8
- Added a "use utf8;" line in code
- Added a "binmode(STDOUT, ":utf8");" line in code

And accentuated character doesn't appear well. If I save source code as
ISO-8859-1, all sounds right. So, I'm wondering if they didn't been UTF-
8 encoded twice.

Well, searching further, I've found that the project I told about (there
several, but I've started with this one) is using several source files
(the main one using require to use the others one) and that I didn't
added the "use utf8;" line in every file. Now, I've done-it, saved full
sources in UTF-8 and these literal strings are well displayed in
browser. Don't know if it's the right way (tell me please), but it
works.
 
B

Bart Van der Donck

Yohan said:
Using Perl 5.8.8, I'm trying to found the best way to support UTF-8
everywhere about outputted literal strings (from source code) toward
generated UTF-8 HTML in browser.

I've done this :
- Saved source code (containing the literal strings) as UTF-8
- Added a "use utf8;" line in code
- Added a "binmode(STDOUT, ":utf8");" line in code

[...]

I would counsel to add the following:
- Set the charset of the output stream to utf8
- Set the webpage's <meta http-equiv="Content-Type"> to utf8

Like:

#!/usr/bin/perl
use strict;
use warnings;
print <<'HTML'
Content-Type: text/html; charset=utf-8

<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=utf-8">
</head>
<body>pretty sure we are in utf-8 now</body>
</html>
HTML

Hope this helps,
 
D

Dr.Ruud

Bart Van der Donck schreef:
I would counsel to add the following:
- Set the charset of the output stream to utf8
- Set the webpage's <meta http-equiv="Content-Type"> to utf8

Like:

#!/usr/bin/perl
use strict;
use warnings;

Missing:

binmode( STDOUT, ':utf8' ) ;

or (maybe slightly more accurately)

binmode( STDOUT, ':encoding(UTF-8)' ) ;

See perluniintro for details.
 
B

Bart Van der Donck

Dr.Ruud said:
Bart Van der Donck schreef:


Missing:

binmode( STDOUT, ':utf8' ) ;

or (maybe slightly more accurately)

binmode( STDOUT, ':encoding(UTF-8)' ) ;

See perluniintro for details.

Yes but I think he already had that (among others) in his list. I
wouldn't know which other things he might add though - AFAIK that
should be as complete as it can be.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top