You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Brian Dimeler <br...@lserve.com> on 2005/05/05 20:15:13 UTC

[mp1] binmode(STDOUT, ':utf8') fails silently

Hi, I'm trying to set binmode(STDOUT, ':utf8') from within a PerlRun script (mod_perl 1.29, apache 
1.3.29, perl 5.8.6), and it's failing (returning undef) without setting $!, as the docs claim it 
should.

I really shouldn't even have to do this at all, since I'm already setting

Content-type: text/html; charset=UTF-8

as the header,

<?xml version="1.0" encoding="UTF-8"?>

at the start of the document AND, just to be thorough,

<meta http-equiv="Content-type" content="text/html; charset=UTF-8"/>

in the <head> section of all my generated HTML. When I invoke my script at the command line, the 
output shows up in the terminal with the proper unicode characters. Málaga is Málaga. But the same 
script, when run by mod_perl, sends "Málaga" to the browser instead. Why is this, and why is it 
that the only obvious workaround, binmode(), has decided to quietly quit? (and yes, I'm setting 
binmode() before using print() for for the first time).

Let me know if that's not enough information. Unfortunately I cannot post the entire script in a 
public forum.

Re: [mp1] binmode(STDOUT, ':utf8') fails silently

Posted by Markus Wichitill <ma...@gmx.de>.
Brian Dimeler wrote:
> Ha, nevermind, I figured it out. Turns out that when a param was sent to 
> the script indicating a cookie should be changed, it was using CGI's 
> header() function to generate the header rather than my header text. 
> Adding -charset => 'UTF-8' to header() did the trick, naturally.
> 
> Still curious about binmode(), though; is there some mod_perl-specific 
> reason that it would fail?

Under mod_perl 1.x, binmode() is just a stub that does nothing. Should 
probably be fixed to return true.

It's under mod_perl 2.x where things get really interesting. There you have 
tied IO or PerlIO, and actually need to call binmode(). And calling it just 
before the first print() doesn't seem always enough either, I had to move it 
rather close to the script start.

Re: [mp1] binmode(STDOUT, ':utf8') fails silently

Posted by Brian Dimeler <br...@lserve.com>.
Ha, nevermind, I figured it out. Turns out that when a param was sent to the script indicating a 
cookie should be changed, it was using CGI's header() function to generate the header rather than my 
header text. Adding -charset => 'UTF-8' to header() did the trick, naturally.

Still curious about binmode(), though; is there some mod_perl-specific reason that it would fail?

Brian Dimeler wrote:

> Hi, I'm trying to set binmode(STDOUT, ':utf8') from within a PerlRun 
> script (mod_perl 1.29, apache 1.3.29, perl 5.8.6), and it's failing 
> (returning undef) without setting $!, as the docs claim it should.
> 
> I really shouldn't even have to do this at all, since I'm already setting
> 
> Content-type: text/html; charset=UTF-8
> 
> as the header,
> 
> <?xml version="1.0" encoding="UTF-8"?>
> 
> at the start of the document AND, just to be thorough,
> 
> <meta http-equiv="Content-type" content="text/html; charset=UTF-8"/>
> 
> in the <head> section of all my generated HTML. When I invoke my script 
> at the command line, the output shows up in the terminal with the proper 
> unicode characters. Málaga is Málaga. But the same script, when run by 
> mod_perl, sends "Málaga" to the browser instead. Why is this, and why 
> is it that the only obvious workaround, binmode(), has decided to 
> quietly quit? (and yes, I'm setting binmode() before using print() for 
> for the first time).
> 
> Let me know if that's not enough information. Unfortunately I cannot 
> post the entire script in a public forum.
>