Sorry, there was a missing tag in the xml file from my previous post. ---------------------


Hello,

I have the following simple script to parse shift-jis XML. However, the script crashes every time I run it with a "Segmentation fault" after the first sleep. That is it crashes when starting the second thread on the second iteration of the while loop. Specifically, the crash occurs just before the safe_parsefile() is called during the second thread. I tried the script both on perl 5.8.0 and 5.8.5. Could it be that the first thread is not cleaning up some file handle? I have no way of telling. Please help! I don't know what's happening.

#!/usr/bin/perl use XML::Twig; use LWP::UserAgent; use Thread; $userAgent = new LWP::UserAgent; $userAgent->timeout($connectTimeout); while (1) { my $thread = threads->new(\&querySystem); $thread->join; sleep 5; } sub querySystem { my $statusCallback = queryStatus(); my $statusTwig = new XML::Twig(twig_roots => {'Result/Status' +=> $statusCallback }, ProtocolEncoding=>"x-sjis-unicode"); my $result = $statusTwig->safe_parsefile("xmlfile.xml"); } sub queryStatus { my $newfunc = sub { my($twig, $element) = @_; my $mmsVersion = $element->first_child('MMSVersion')-> +text; my $partVersion = $element->first_child('ParticipantVe +rsion')->text; print "mmsVersion: $mmsVersion, partVersion: $partVers +ion\n"; }; return $newfunc; }
The XML file looks as follows:
<?xml version="1.0" encoding="shift-jis"?> <!DOCTYPE AdminRequest SYSTEM "AdminAPI.dtd"> <AdminRequest> <Header> <ReturnCode>0</ReturnCode> <ReturnString></ReturnString> </Header> <Results> <Result Id="123455"> <Action>query_status</Action> <ReturnCode>0</ReturnCode> <ReturnString></ReturnString> <Status> <MMSVersion>2.1.74G</MMSVersion> <ParticipantVersion>4.8.1565B</ParticipantVersion> <MMSMajorVersion>5.1 jp</MMSMajorVersion> + </Status> </Result> </Results> </AdminRequest>

In reply to Script crashes when parsing XML by jabarin

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.