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

Hola Senors y Senioritas: Does anyone know why XML::Twig would dump core when perl (perl v5.8.0 on sun4-solaris) is done executing a program? Their are two odd things about this anomaly: 1) The program that is using the module (code included below) seems to be working perfectly 99% of the time with data sources that are similar to the one that is failing (the failing XML source can be found at http://www.statenet.com/sama/BILLTEXT_20011025_0_N.xml). 2) The program actually gives correct output if STDOUT is autoflushed. However, after the program exits (I tested this by printing a line of text to STDERR just before the end of the code), it seems that perl dumps core. The perl source is listed below:
#!/usr/local/bin/perl use strict; (my $prog = $0) =~ s-.*/--; my $usage = "USAGE: $prog xml_file"; @ARGV == 1 or die "$usage\n"; # $xml_file = http://www.statenet.com/sama/BILLTEXT_20011025_0_N.xml my ($xml_file) = shift; unless (-f "$xml_file" ) { die "$prog: FATAL: File: $xml_file does not exist\n"; } use DBI; use XML::Twig; my $twig = XML::Twig->new( pretty_print => 'indented', load_DTD => 1, ); unless ( $twig->safe_parsefile($xml_file) ) { die "$prog: FATAL: Failed parse of $xml_file...\n"; } my $root = $twig->root(); my $billtext = $root->children('billtext'); my $version_date_xml = $billtext->first_child('billtext_version_date') +; my $version_date = $version_date_xml->text; my $verseq = parse XML::Twig::Elt("<billtext_version_sequence>0</billt +ext_version_sequence>"); $verseq->paste(after => $version_date_xml); $twig->flush(Update_DTD => 1); # print(STDERR "Hey, look, I still haven't dumped core!!!\n");

Replies are listed 'Best First'.
Re: XML::Twig dumping core on valid XML...
by samtregar (Abbot) on Nov 30, 2005 at 19:36 UTC
    Try upgrading your Perl. 5.8.0 is very old and had lots of bugs that could cause problems like this.

    -sam

Re: XML::Twig dumping core on valid XML...
by Tanktalus (Canon) on Nov 30, 2005 at 20:32 UTC

    To reiterate what samtregar says - I actually had this problem. Upgrading to 5.8.1 solved the problem for me. As long as you're upgrading anyway, I'd suggest going to 5.8.7 which has solved other memory problems for me as well.