perl: November 2008 Archives
Many many times I have suffered undue pain when using perl with XML. Anything using SOAP::Lite, XML::Simple, XML::Feed is more often than not affected by incredibly slow XML parsing. This in turn is more often than not down to the lack of certain C or CPAN libraries; out of date or poorly configured XML::SAX or XML::Parser modules; or any combination of all these factors.
The answer is, almost always, to (re)install a few things to get a great performance boost. Here's what I remember from fixing up a fairly standard Debian 4.0 (etch) install which came with perl 5.8.8:
Use aptitude to install or upgrade the following packages:
apt-get install libxml-sax-perl apt-get install libxml-sax-expat-perl apt-get install libxml-libxml-perl
Now the advantage of using apt to do the install is that it will find the all important missing C libraries and install them too. libxml2 and xml-core are the two C libraries that I recall.
Then, reinstall XML::SAX using CPAN:
cpan XML::SAX
Hopefully, that will go smoothly.
Here's where things get messy: Now you need to uninstall the XML::SAX that you install with apt because apt - at the time of writing (atow) ships version 0.12 whereas the latest version - 0.96 atow - has many fixes. You need to uninstall it because although you have installed the latest version using CPAN, apt and cpan tend to install packages in different locations on your machine.
So, find all versions of XML::SAX on your machine. I use locate for this:
updatedb locate /XML/SAX.pm
If you find more than one copy of XML::SAX check each version that your find all but the most recent one.
Make sure XML::SAX knows about the parsers we just installed.
XML::SAX picks a parser based on what's in ParserDetails.ini so you need to make sure your parsers are in there.
http://perl-xml.sourceforge.net/faq/ is a great guide to many of these things and
perl -MXML::SAX -e "XML::SAX->add_parser(q(XML::LibXML::SAX))->save_parsers()"
Does the job.
Sometimes trying to apt-get install libxml-sax-perl keeps returning a could not configure XML::SAX error.
You probably installed XML::SAX using cpan and the old version was deleted (either automatically, or manually) before you apt installed the XML parsers. Well, this is a pain as apt will keep on moaning about it every time you use it. So my solution is to edit
/var/lib/dpkg/status
To say that it is installed, e.g.
Package: libxml-sax-perl Status: install ok installed
