I am building XML sitemaps with XML::Twig::Elt. And I think am am handling it wrongly as it runs into a segmentation fault although it seems to be a proven module.
sub add_html { my $self = shift; my $ref = shift; # step over elements in fixed order my @elements; foreach my $key (qw(loc changefreq lastmod priority)){ if($key eq 'loc'){ if($ref->{loc}){ push(@elements, XML::Twig::Elt->new('l +oc', {}, $ref->{loc}) ); }else{ print "Error: 'loc' is a mandatory val +ue and missing!\n" } }elsif($key eq 'priority'){ if($ref->{priority}){ push(@elements, XML::Twig::Elt->new('p +riority', {}, $ref->{priority}) ); }else{ print "Error: 'priority' is a mandator +y value and missing!\n" } } } # wrap these sub-elements into an "url"-level my $elt = XML::Twig::Elt->new('url', {}, @elements); undef(@elements); # and add this url-sub-element nest to the xml-document $elt->paste(last_child => $self->{xml}); $self->{cnt}->{html}++; }
As it seems I get the segfault on large structures, after a few thousand inserts, at least it segfaults after ~ 50000 calls to the code above. The function triggering the error is the ->paster() bit.

Could be XML::Twig::Elt has problems handling large structures. I would refactor my module then to write to file in smaller chunks. But before I do that I'd like to ask if someone sees what I am doing wrong here.

Any ideas?

In reply to Segmentation fault from XML::Twig::Elt by isync

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.