justibus has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I am trying to edit a xml file using XML::Twig, but perl always crashes on outputting the xml to a new file. Now, this already happens when I don't do anything to the file, just parse it and print it to another file. I've traced the problem to the cleanup routine in XML::Twig using the Devel::ptkdb debugger, it happens somewhere in the vicinity of line 7535 in Twig.pm (I use the newest version 3.39 of XML::Twig, and strawberry perl 5.12.3).

Sometimes there's also a memory leak and I get a message "Out of memory!". The crash itself doesn't produce any error messages in perl, aside from the message in Windows 7 that perl.exe has crashed.

The xml file can be found here: http://dl.dropbox.com/u/14595053/test.zip (45 kb, 1.7 MB expanded). I have zipped it and uploaded it to dropbox because it's quite big. I have validated it with several tools and all say, that it's a valid xml file.

use strict; use warnings; use XML::Twig; my $xml = new XML::Twig(); $xml->parsefile('test.xml'); open OUT, ">", "test.new.xml"; $xml->print(\*OUT); close OUT;
Does anybody know, what's going on? Thanks!

Edit: The workaround I found is to downgrade to perl 5.10.1.5.

Replies are listed 'Best First'.
Re: perl crashes when processing xml with XML::Twig
by choroba (Cardinal) on Mar 12, 2012 at 22:31 UTC
    After fixing a bug (Global symbol "$file" requires explicit package name ...), your code runs fine for me.
      Hmm, what perl version are you using (and what operating system)? I suspect it's the perl environment that causes the problem. I have tried both strawberry perl 5.12.3.0 and 5.14.2.1 on Windows 7. And I fixed the bugs. I made mistakes during copy and paste.
        Linux (openSUSE 12.1), perl 5.14.2.
Re: perl crashes when processing xml with XML::Twig
by Anonymous Monk on Mar 13, 2012 at 03:31 UTC
    Make sure Task::Weaken is installed
      It is already installed: "Task::Weaken is up to date (1.04)". According to the readme of XML::Twig, to reduce memory leaks, I also have Scalar::Util and WeakRef installed. The problem still persists.

        It is already installed: "Task::Weaken is up to date (1.04)". According to the readme of XML::Twig, to reduce memory leaks, I also have Scalar::Util and WeakRef installed. The problem still persists.

        It's not that I don't believe you , but, well, I don't :)

        Any perl I try it just works, 5.12.2,5.14.1,5.14.2, even just now for curiosity sakes strawberryperl 5.12.3.0, no problem whatsoever.

        Try uninstalling WeakRef?