Re: entity euro hurts

Jean-Michel Hiver <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.petal
Message-ID <[email protected]>
Michele Beltrame wrote:

>Hi Jean!
>
>  
>
>>In MKDoc/XML/Decode/XHTML.pm, euro points to the decimal value 8364. 
>>Since this is a unicode high value, Perl has to upgrade all your strings 
>>to unicode. Hence, whenever you use &euro; symbol the resulting string 
>>will be UTF-8 rather than latin1.
>>    
>>
>
>Just a final question. As said, I now output UTF8 to the browser (setting
>the appropriate charset in the HTTP header and meta tag). This however
>works until the string (parsed template) I send is really UTF8, that
>it to say when I include something that produces an Unicode high value, such
>as "&euro;". If I don't do this, Perl doesn't convert its strings to UTF8
>and they remain latin1.
>
>This behavious causes the browser (I use Mozilla Firefox under Linux/GTK) to
>work just fine if the string is really Unicode, but not that good if
>it's not. So, if I don't include an "&euro;" in my template, "&nbsp;"
>charachters are shown as a square with FFDD inside (which means that
>Mozilla does not own a proper char to dislay).
>

You have to use the Encode module to make sure your data is always UTF-8.

use Encode;
my $string = $template->process (%stuff);
$string = Encode::encode ('utf8', $string);

Cheers,
Jean-Michel.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.