Hello. This is my first question so my apologies in advance if I break any taboos. I did read the formatting tips and how to ask a question articles.
From a high level I am trying to write an XML parser. I'm using XML::Simple to get the XML into a hash and am then navigating that hash to pull out the data I need. In the hash that XML::Simple gives me, there is an array of hashes, and while looping through those I have a problem with the structure below:
'user' => { + 'firstname' => 'Joe', + 'lastname' => 'Shmoe', }, 'user' => 'Finance Department'
What I want to do is print out either the user's full name OR the department if there is no substructure under the user reference. However, I get a "Can't use string ("Vox Procurement Managers") as a HASH ref while "strict refs" in use at Code.pl line 138." error when the code gets to the Finance Department bit. I've tried checking if(exists $xml->$usernumber->{"user"}->{"firstname"} before trying to print the full name but that still throws the error. Further googling and searching here has not helped. Basically I need a way to check if that reference in the hash points to a string ("Finance Department") or to more hashes down below. An if statement based on if( ref ($xml->$usernumber->{"user"}}) eq "HASH") always returned true and did not work either.
In reply to Parsing hashes with variable structure by SomeNoob
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |