perl-unicode

Re: Interpretation of non-UTF8 strings

2004-08-16 08:30:07

Gee, thanks, in that case could everyone please erase from their minds
what I just said :-)  Normally people just bitch on and on about how
Perl's Unicode is sooo broken, which is not exactly a motivation builder
for me...

Well, I think that their frustration comes from not understanding how Unicode works... While it's true that Perl might be still rough on the edges (especially third party modules such as CGI.pm which have to maintain compatibility with dinosauresques versions of Perl), if you sort of know what you're doing + you use Encode, then it's fine...

For reference, this site: http://www.multikulti.org.uk/ runs with our CMS software (which is written in Perl of course) and as you can see that Perl seems to be doing okay... I really like the arabic section since everything flips right to left.


To make it all work I just had to:

- Subclass CGI.pm (so that strings are marked as UTF-8)

- Write an SQL layer that marks all the string that come from MySQL as UTF-8 (3.21 doesn't support unicode but it doesn't mean that you can't store Unicode text in Blobs...). For good measure, I also make sure that all the strings are stored in NFC (useful for searches and stuff when using a non-unicode aware system...)

- Make my templating system Petal slightly aware of Unicode and serve all the pages as UTF-8.

And then whamo! Everything works fine. As long as you make sure that your strings are properly encoded in Perl's internal format, "It Just Works..."

In comparison whith what I had to do with 5.6.0 (which didn't even concatenate two unicode strings properly) and 5.6.1 (where I had to use UTF8::Hack, mark / unmark UTF-8 strings manually, and use a bunch of CPAN Unicode::* modules) the 5.8.x series works like a charm.

So I've got only one thing to say: thanks guys!


NB : For those interested in web applications, templating systems and localization, search on search.cpan.org for:

- Petal::I18N - http://search.cpan.org/~jhiver/Petal/lib/Petal/I18N.pm
- I18NFool - http://search.cpan.org/~jhiver/I18NFool/lib/I18NFool.pm

Hopefully you'll find the stuff there interesting - and I would certainly welcome some feedback!

<Prev in Thread] Current Thread [Next in Thread>