Your skill will accomplish what the force of many cannot |
|
PerlMonks |
Re: XML::Simple - Invalid file contentby ELISHEVA (Prior) |
on Sep 22, 2009 at 09:52 UTC ( [id://796699]=note: print w/replies, xml ) | Need Help?? |
To avoid dying, surround the call to XMLin with an eval statement like this:
The above code has one problem though. If you have a lot of things you are going to do with $ref, you'll probably want to halt processing whenever you see a problem. Also if you put too much code in eval {...} you might have things that die and aren't due to invalid content, but rather to something you did with valid content after you put it in the XML file. You might prefer something like this:
Note: I changed your output stream to STDERR. In almost all cases it is better to send error messages to STDERR rather than STDOUT (print "some string" sends output to STDOUT). That way you can keep your "real output" separate from your logging, debugging and error messages. Best, beth
In Section
Seekers of Perl Wisdom
|
|