Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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

In reply to XML::Simple isn't simple! by r.joseph

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2021-11-30 16:08 GMT
Find Nodes?
    Voting Booth?

    No recent polls found