in reply to Script crashes when parsing XML

Here is a way to make it work, which only creates a single XML::Twig object in the thread, then reuses it. (Also its 'use threads', not 'use Thread'. I made it as simple as I could for clarity. Threads need to go to the end of their code block in order to be joined, but a return will work as well. Anyways, this creates 1 thread, and 1 XML::Twig object, then reuses it.
#!/usr/bin/perl use warnings; use strict; use threads; use threads::shared; my $tgo; my $tdie; my $tfile; share $tgo; share $tdie; share $tfile; $tgo = 0; $tdie = 0; $tfile = ''; my $thread = threads->new(\&querySystem); foreach my $file('xmlfile.xml', 'xmlfile.xml' ){ $tfile = $file; $tgo = 1; sleep 5; } $tdie = 1; $thread->join; print "done press any key to exit\n"; <>; ################################################### sub querySystem { use XML::Twig; $|++; my $statusTwig = new XML::Twig( twig_roots => {'Result/Status' => sub{ my($twig, $element) = @_; my $mmsVersion = $element->first_child('MMS +Version')->text; my $partVersion = $element->first_child('Pa +rticipantVersion')->text; print "mmsVersion: $mmsVersion, partVersion +: $partVersion\n"; } }, ProtocolEncoding=>"x-sjis-unicode"); while(1){ if($tdie == 1){ goto END }; if ( $tgo == 1 ){ my $result = $statusTwig->safe_parsefile($tfile); $tgo = 0; #turn off self before returning }else { sleep 1 } } END: } __END__

I'm not really a human, but I play one on earth. Cogito ergo sum a bum