I'm having a really hard time reading your example (please use code tags?).. Understanding your result is difficult too. I'll make some "guesses" at what you might be trying to do and hope this helps...
I really do not know what you meant to do with the XML document you posted from your comments, so I am left to guess at what you meant to do. Here is my version:
<hosts>
<host name="jimmy">
<function>web</function>
<function>dns</function>
<location>miami</location>
</host>
<host name="haffa">
<function>nfs</function>
<function>quake</function>
<location>hell</location>
</host>
</hosts>
Now here's the code to parse it: (I did not know what you meant to do with the hash you passed into XMLin, so I removed it)
use XML::Simple;
use Data::Dumper;
# create object
my $xml = new XML::Simple ();
# read XML file
my $data = $xml->XMLin("/tmp/hosts.xml");
print Dumper($data);
And here is the output:
$VAR1 = {
'host' => {
'haffa' => {
'function' => [
'nfs',
'quake'
],
'location' => 'hell'
},
'jimmy' => {
'function' => [
'web',
'dns'
],
'location' => 'miami'
}
}
};
I think the results are fairly self-explanatory?
- dEvNuL
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.