in reply to Re^2: Examples where XML::Simple is the optimal choice?
in thread Examples where XML::Simple is the optimal choice?

What I'm trying to get to is - I'm feeling like I'm banging on saying "Just don't use XML::Simple, there are no good reasons to" and I'm after counter examples. Niches where it isn't just plain worse.

You need to ask more noobs

:) new things are scary, only noobs can come up with examples, because they like trying to write {foo}{bar} (but can't debug it)

{foo}{bar} is better documented and more accessible to noobs than the others

twig has too much documentation :D

libxml docs don't teach you xpath or trees/dom or ...perlintro

so they think "xml hash" and go searching .... after half hour of frustration they stumble upon XML::Simple

Its why I try to give libxml examples often ... its 98% copy/paste

Its also why I link threads where libxml/rules/simple/twig solutions are present....

but even with all that compare/contrast, noobs like to inch through xml/hashes while simultaneously trying to learn perlintro

they need handholding

I used to :D

  • Comment on Re^3: Examples where XML::Simple is the optimal choice?

Replies are listed 'Best First'.
Re^4: Examples where XML::Simple is the optimal choice?
by Preceptor (Deacon) on Oct 23, 2015 at 10:28 UTC

    Honestly though - What you get from XML::Simple isn't AT ALL simple. You need to set a bunch of (non default) options just to get something consistent out of it. Once you've done this, you end up with a daisy chain of array and hashes that you've no hope of navigating without referring to Data::Dumper.

    But yes, perhaps I need to ask more noobs, but they don't actually see the difference between a hacky bodge and some code that's just as efficient but way clearer.

Re^4: Examples where XML::Simple is the optimal choice?
by Preceptor (Deacon) on Oct 23, 2015 at 21:53 UTC

    Actually, thinking about it - one of the fundamental problems here, is that the transformation between XML to has breaks down - because what you have in XML is:

    • Nodes beneath the same parent with the same name
    • Ordered named nodes
    • Attributes - which logically would be a hash, but if they do, they contend with children

    So with that in mind - you can craft XML that passes through XML::Simple painlessly by not doing any of those things:

    <xml> <element>value</element> <another_element>a different value</another_element> </xml>

    The irony is though - if your XML is that simple, then you didn't need XML::SImple either:

    my %stuff = $xml =~ m/(\w+)>([^<]+)</g;

    But as we know - it's a bad idea to parse XML with a regex - I think it's a bad idea to use XML::Simple for exactly the same reasons. (And you need to install it too)