[Petal] How to use UtF-8 characters in Petal Templates
Stefan Seifert
nine at detonation.org
Thu Sep 27 13:05:45 GMT 2012
Hi,
On Thursday 27 September 2012 14:25:11 Peter Mayr wrote:
> we really like the Petal Templating-Engine for our webservices, however
> I ran into a small problem:
> How can I use UTF-8 characters in Templates?
> It seems to me that they are all encoded to ISO-Latin-1.
>
> Does anyone of you have some tips or pointers?
Your issue is not with Petal, but with Perl in general. $Template->process()
gives you a Perl Unicode character string. It's your responsibility to encode
it according to your needs (that would be UTF-8) on output. Simply doing a
print in your test script will encode the character string to the platform
encoding (usually latin-1).
Same would happen if you just printed some constant Unicode string:
perl -E 'use utf8; say "ödögödöckö";'
To get UTF-8 output, you could use binmode:
perl -E 'use utf8; binmode STDOUT, ":utf8"; say "ödögödöckö";'
Have a look at https://metacpan.org/module/perluniintro for further
information about how to use Unicode in Perl. And remember: debugging
character encoding problems _sucks_ because everything has been processed by
multiple programs before reaching your eye (for example by your program, Perl,
your shell, your terminal, ...). Always make sure that you know exactly how
your data looks like every step of the way. If in doubt, use hexdump.
Regards,
Stefan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <https://lists.webarch.co.uk/pipermail/petal/attachments/20120927/6826999b/attachment.bin>
More information about the Petal
mailing list