Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: help to preserve the order of hash

by herveus (Parson)
on Jun 23, 2010 at 17:46 UTC ( #846127=note: print w/ replies, xml ) Need Help??


in reply to help to preserve the order of hash

Howdy!

Let me call your attention to the documentation for XML::Simple, in particular the part where it notes some assumptions that must hold. Specifically, the part where it says "You don't mind that when things get slurped into a hash, the order is lost".

It notes that "...you'll probably outgrow these assumptions fairly quickly". You probably need to switch to another module.

yours,
Michael


Comment on Re: help to preserve the order of hash
Re^2: help to preserve the order of hash
by LanX (Canon) on Jun 23, 2010 at 17:56 UTC
    > You probably need to switch to another module.

    actually there are options like "force array".

    Cheers Rolf

      Howdy!

      True, but it does not appear to do what the OP needs. As I read the POD, it appears that the top level structure returned by XMLin is always a hashref. At any given level, the keys in the hash are the distinct tags that appear at that level. If there are multiple instances of a tag, each instance is an element in an array of hashes.

      ForceArray simply forces that behavior even if there is only one instance of the tag. It does not appear that there is any way to make XMLin return an arrayref.

      The POD does describe the limitations, and the OP has run smack into one of them. The suggested course of action is "use a different module". Hacking (for some value of "hacking") XML::Simple to use Tie::IxHash internally is certainly one way to go there; the OP will have to decide which approach will work best for this problem.

      yours,
      Michael
        > Howdy!

        Gr Gott! :)

        Sure I was wondering myself about the hashref, but I didn't (and still don't) want to dig to deep into the problem, (just communicate the little bit of observation:)

        Cheers Rolf

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2014-12-23 03:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (134 votes), past polls