Given the following small XML file:
<operating_systems>
<os score="10" name="Linux" />
<os score="7" name="BeOS" />
<os score="-999999999" name="Windows 9x" />
</operating_systems>
...and the following code snippet:
#!/usr/bin/perl
use warnings;
use XML::Simple;
use Data::Dumper;
my $file = './os.xml';
my $ref = XMLin($file);
print $ref{'os'}->{'Linux'}->{'score'};
...with the resulting data structure in
$ref looking like:
$VAR1 = {
'os' => {
'BeOS' => {
'score' => '7'
},
'Windows 9x' => {
'score' => '-999999999'
},
'Linux' => {
'score' => '10'
}
}
};
one would expect that the
score value for
Linux would be printed, which should be, in this case, 10.
Then
why oh why does this script instead print nothing at all?!
Oh
XML::Simple, why can't you just be SIMPLE?
r.
j
o
s
e
p
h
"Violence is a last resort of the incompetent" - Salvor Hardin,
Foundation by Issac Asimov
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.