Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Behaviour of parsed XML

by cavac (Curate)
on Feb 26, 2020 at 14:05 UTC ( #11113439=note: print w/replies, xml ) Need Help??


in reply to Behaviour of parsed XML

Try:

my $xml = XMLin($filename, ForceArray => ['item'];

perl -e 'use Crypt::Digest::SHA256 qw[sha256_hex]; print substr(sha256_hex("the Answer To Life, The Universe And Everything"), 6, 2), "\n";'

Replies are listed 'Best First'.
Re^2: Behaviour of parsed XML
by dalgetty (Acolyte) on Feb 26, 2020 at 16:17 UTC

    Wow.

    cavac

    That just worked. Like a turnaround jumpshot. Thanks to everybody for your help, it's all good now...

      It might solve this particular issue, but in general moving away from XML::Simple will serve you better long term. The module is conceptually broken. It treats XML as being basically weird-looking JSON. But XML's data model is entirely different than JSON's. Not going to get into a debate about which data model is better, but treating them the same is like writing flight-planning software that will only generate flight routes that follow highways.

      Somebody else recommended XML::Rules, which is probably the easiest thing to transition to from XML::Simple. It still allows you to treat the XML like glorified JSON, but requires you to give it rules about how to translate between the models, with some sane defaults.

      The other thing I'd recommend looking at is XML::LibXML, which provides a full DOM API for XML, which will be pretty familiar if you've done any client-side Javascript programming.

        Well, that really depends on what you are trying to do. I'm using XML::Simple as my config parser for most of my projects reliably for over a decade.

        Would i use XML::Simple to work with Wikipedia exports? Heck no, that would be a major pain.

        Would i use XML::LibXML to parse a simple config file? Heck no, this would be total overkill and would waste a lot of developer time.

        The right tool for the right job. You know, TIMTOWTDI

        perl -e 'use Crypt::Digest::SHA256 qw[sha256_hex]; print substr(sha256_hex("the Answer To Life, The Universe And Everything"), 6, 2), "\n";'

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11113439]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2021-01-18 00:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?