Re: How to use UtF-8 characters in Petal Templates

Stefan Seifert <nine-cGv6mBdbfPVxtahE/[email protected]> Thu, 27 Sep 2012 15:05:45 +0200
Newsgroups gmane.comp.lang.perl.modules.petal
Message-ID <[email protected]>
--nextPart3160331.YaviiNz0U7
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="utf-8"

Hi,

On Thursday 27 September 2012 14:25:11 Peter Mayr wrote:

> we really like the Petal Templating-Engine for our webservices, howev=
er
> 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.
>=20
> Does anyone of you have some tips or pointers?

Your issue is not with Petal, but with Perl in general. $Template->proc=
ess()=20
gives you a Perl Unicode character string. It's your responsibility to =
encode=20
it according to your needs (that would be UTF-8) on output. Simply doin=
g a=20
print in your test script will encode the character string to the platf=
orm=20
encoding (usually latin-1).

Same would  happen if you just printed some constant Unicode string:
perl -E 'use utf8; say "=C3=B6d=C3=B6g=C3=B6d=C3=B6ck=C3=B6";'

To get UTF-8 output, you could use binmode:
perl -E 'use utf8; binmode STDOUT, ":utf8"; say "=C3=B6d=C3=B6g=C3=B6d=C3=
=B6ck=C3=B6";'

Have a look at https://metacpan.org/module/perluniintro for further=20
information about how to use Unicode in Perl. And remember: debugging=20=

character encoding problems _sucks_ because everything has been process=
ed by=20
multiple programs before reaching your eye (for example by your program=
, Perl,=20
your shell, your terminal, ...). Always make sure that you know exactly=
 how=20
your data looks like every step of the way. If in doubt, use hexdump.

Regards,
Stefan
--nextPart3160331.YaviiNz0U7
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: This is a digitally signed message part.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.19 (GNU/Linux)

iEYEABECAAYFAlBkTysACgkQ1QuEJQQMVrivwwCdF82x2cXB9IlfzC5SVxlMT5BF
PKoAn1wcC6HFOPh/CHTdndS3SoaNCz50
=Q9oc
-----END PGP SIGNATURE-----

--nextPart3160331.YaviiNz0U7--