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

I'm using XML::Parser::Lite on AIX 5.0.0.0 and working with the following document:
<foo/>

I can do the following:

use strict; use warnings; use XML::Parser::Lite; my $doc = "<foo/>\n"; print "'$doc'\n"; my $parser = XML::Parser::Lite->new( Handlers => { Start => sub { shift; print "Start: @_\n"; }, Char => sub { shift; print "Char: @_\n"; }, End => sub { shift; print "End: @_\n"; }, }, ); $parser->parse($doc); print "Finally done\n"; -------- '<foo/> ' Start: foo End: foo Finally done

But, the following code produces a different error (sometimes in a different place), depending if I use perl5.6.0, perl5.8.0, or perl5.8.1:

Foo/Bar.pm package Foo::Bar; sub new { bless {} } 1; __END__ ---- main.pl use strict; use warnings; use XML::Parser::Lite; my $doc = "<foo/>\n"; print "'$doc'\n"; my %Names = ( foo => 'Foo::Bar', ); my @stack; my $parser = XML::Parser::Lite->new( Handlers => { Start => sub { shift; print "Start: @_\n"; my $pkg = shift; (my $name = $Names{$pkg}) =~ s!::!/!g; $name .= '.pm'; eval { require $name; }; if ($@) { die "Cannot require '$name' ($pkg)\n"; } my $x = $Names{$pkg}->new(@_); push @stack, $x; }, End => sub { shift; print "End: @_\n"; pop @stack if @stack; }, }, ); $parser->parse($doc); print "Finally done\n";

Under 5.6.0, it says:

'<foo/> ' Start: foo 50356: terminated with signal 4 -- core dumped

Under 5.8.0, it says:

'<foo/> ' Start: foo 13000: terminated with signal 11 -- core dumped

Under 5.8.1, it goes farther and says:

'<foo/> ' Start: foo End: foo corrupted regexp pointers at (eval 1) line 1.

I am stumped. I can't use XML::Parser because I can't install expat on this machine. Help!

------
We are the carpenters and bricklayers of the Information Age.

The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

... strings and arrays will suffice. As they are easily available as native data types in any sane language, ... - blokhead, speaking on evolutionary algorithms

Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Replies are listed 'Best First'.
Re: XML::Parser::Lite coredumping
by mirod (Canon) on Oct 17, 2003 at 20:20 UTC

    For some reason XML::Parser::Lite doesn't like the regexp you are using (the parser is regexp-based, and there is some really scary regexp stuff going on inside).

    This works on my 5.8.1 (which otherwise gives me yet a different error, a SegFault):

    my $name= join '/', split /::/, $Names{$pkg};

    If it doesn't work for you, try something else, like having the file name built outside of the parser loop:

    #!/usr/bin/perl -w use strict; use XML::Parser::Lite; my $doc = "<foo/>\n"; print "'$doc'\n"; # you could of course build the file name from the package name here # instead of just having it hard-coded my %Names = ( foo => { file => 'Foo/Bar.pm', package => 'Foo::Bar'}, ); my @stack; my $parser = XML::Parser::Lite->new( Handlers => { Start => sub { shift; print "Start: @_\n"; my $pkg = shift; eval { require $Names{$pkg}->{file}; }; if ($@) { die "Cannot require ' $Names{$pkg}->{f +ile}' ($pkg)\n"; } my $x = $Names{$pkg}->{package}->new(@_); push @stack, $x; }, End => sub { shift; print "End: @_\n"; pop @stack if @stack; }, }, ); $parser->parse($doc); print "Finally done\n";
Re: XML::Parser::Lite coredumping
by BrowserUk (Patriarch) on Oct 17, 2003 at 21:40 UTC

    As the handlers are called from within an executing regex via (?{}) code blocks, the module should probably carry a "No regexes in handlers" warning. It even uses some loops to avoid using split internally, that ought really be mentioned.

    Wicked code though:)


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    Hooray!