Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^4: Parsing hash from XML::Simple

by Anonymous Monk
on May 17, 2016 at 13:12 UTC ( [id://1163200]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Parsing hash from XML::Simple
in thread Parsing hash from XML::Simple

Thanks for the information, but unfortunately none of the answers helped me. I know I only posted one block of code for only one city, it will be more, but can this one block of code be used to show what I am trying to do? Can it still be looped and display the value of city->name? I tried you suggestion but if I run it it gives me this:
Use of uninitialized value in print at...

And here is the code as you posted
... foreach my $vals (values %{ $xml }) { print Dumper $vals->{city}{name}, "\n"; }
Thanks for trying to help!

Replies are listed 'Best First'.
Re^5: Parsing hash from XML::Simple
by Corion (Patriarch) on May 17, 2016 at 13:18 UTC

    You will need to learn about data structures and how to traverse them. There are already replies with links to perldsc and maybe other tutorials.

    If you refuse to show us the data structure, how do you expect us to give you code that will traverse an unknown data structure?

    If you get errors while traversing your data structure, that usually means that your data structure is not what you think it is.

    Please also note that XML::Simple is a bad choice for ingesting data which may or may not have multiple elements somewhere in its structure. See also the ForceArray parameter in its documentation. But again, this boils down to you not showing the relevant parts of your data structure and your incoming data.

    Until you understand your data structure (by using Data::Dumper), and/or understand what parts of your data structure are arrays and what parts of your data structure are hashes, there is little we can do to help you.

Re^5: Parsing hash from XML::Simple
by NetWallah (Canon) on May 17, 2016 at 14:06 UTC
    The built-in perl debugger is particularly useful in learning, and testing data structure access.

    Run like this:

    perl -d your-program-name.pl
    It has a "h" (help) command to get you started.

    Basically, you will be using the "x" (Examine) command to look at the data.

    See perldebug for details.

            This is not an optical illusion, it just looks like one.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2024-04-16 18:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found