in reply to Strange behaviour with utf8 and wide chars

Assuming this is running in CGI you can do

binmode STDOUT, ':utf8';
and that ought to work. This is required because even though you are telling the browser the data is in UTF-8, you aren't telling Perl to output UTF-8 unless you add that line. See perlunicode and perlio for more.

Update: It has been so long since I used 5.6 I had forgotten about the good point raised by almut. But for heaven's sake, Perl 5.8.1 was released in 2003.

Replies are listed 'Best First'.
Re^2: Strange behaviour with utf8 and wide chars
by isync (Hermit) on Mar 22, 2007 at 23:36 UTC
    Actually I was shocked myseld when I saw the output of $] (perl's version)! But I am running on managed hosting and I am not able to update perl.

    Also, the Encoding module is not available for me, and as it is based on a binary, I can't just upload it to working dir...

    So basically I am stuck here. The old Perl always worked for me, until recently when I startet to wrangle with XML and UTF8. Soon I found out I would need a western to utf8 transcoder - that's when I found out there is really no lightweight alternative to Encoding...

    Back to my question:
    The greek 'y' is in utf8 (at least it should be) (btw: I am getting it from utf8-SQL-db via XML, no problems so far) and printed that way, it turns out right -at least on its own. When I add the "smiley" (which is also utf8, as I understand it...) (generated via the xCode) it seems to change the $string1 to a different utf8 beast... Giving me a strange accented "I" and "1/4" while the "smiley" is smiling just beside the mess.

    Like you pointed out: It might/must be the problem that although I am telling the browser the output is utf8, perl doesn't output it as such (which I don't understand as everything in the html including both strings should be utf8).
    Is there ANY way to do this in 5.6.1, to really output utf8. The "pack" trick mentioned everywhere doesn't seem to work for me... And using "use encoding utf8" commands etc. gives an error...