Using Text::IConv or Unicode::String? Converting UTF8 to ISO-Latin1 in Perl.

For quite a while I’ve been stuck in a project in which I read some some data from a set of XML-files generated from an external program. The data loading smoothly done by XML::Simple, but the fact that the target is a mysql database with ISO-8859-1 (ISO-Latin1) while the XML is encoded in UTF-8 has caused a few problems.

Perl doesn’t AFAIK come with any really good convertion routines with the standard modules, and since I was somewhat familiar with the GNU-projects libiconv it come naturally too look after a perl module that uses it. After a quick search, Text::Iconv was found on CPAN

However I quickly ran into a few problems: Text::Iconv is only as portable as it libiconv – and just having a binary dependency is a hassle when moving between alot of platforms. Text::Iconv also had some of libiconvs strange behaviour and very limited error handling. Sometimes the converted text was streal strange and I has not been very statisfied.

Today I stumbled upon Unicode::String that smoothly convert between utf-8 and differenet charsets. The potential of supported charsets is less than libiconvs – but since it got ISO-Latin1 I am all happy. After a test round I replaced all convertion calls and so far I have not noticed any real performance drain and no problems at all – as of yet.

CPAN <3

Tio senaste: