When using XMLin() (from the XML::Simple module) and a $SIG{__DIE__} handler has been assigned, a symbolic reference error is thrown from XML::Parser::Expat. This seems to be specific to the $SIG{__DIE__} handler, as no other signal handlers seem to be affected. What's more, even though the error is thrown XMLin() still does it's magic and returns the expected hash ref.
use XML::Simple; use Data::Dumper; use strict; # note - added exit(1) to keep things simple $SIG{__DIE__} = sub { print "$_[0]"; exit(1) }; my $xml_str = <<XML; <tag1> <tag2 attr1="foo" /> </tag1> XML my $ret = XMLin($xml_str); print Dumper($ret); __output__ Can't use string ("<tag1> <tag2 attr1="foo" /> </t") as a symbol ref while "strict refs" in use at /usr/lib/p +erl5/site_perl/5.6.0/i386-linux//XML/Parser/Expat.pm line 456.
Now, exactly the same code with the $SIG{__DIE__} line commented out produces the expected
$VAR1 = { 'tag2' => { 'attr1' => 'foo' } };
I've tested this code with perl 5.6.0 and 5.6.1 using the latest versions of both XML::Simple and XML::Parser on Linux and Solaris.
If anyone could point out the error in my, or XML::Simple's madness I'd be a happy monk :-)

broquaint


In reply to XML::Simple conflicts with $SIG{__DIE__} by broquaint

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.