I'm getting the following error while trying to print the value in the following code for the below xml. I have similar scripts working w/o issue, but can't figure this one out. Any assistance would be appreciated.

XML:

<response_xml> <exec_command> <command> show resource usage context brn0ace01 </command> <status code="100" text="XML_CMD_SUCCESS"/> <xml_show_result> <xml_show_resource_usage> <ru_entry> <ru_resource>bandwidth </ru_resource> <ru_current> 2744</ru_current> </ru_entry> <ru_entry> <ru_resource>conn </ru_resource> <ru_current> 500</ru_current> </ru_entry> </xml_show_resource_usage> </xml_show_result> </exec_command> </response_xml>

Script:

use XML::Simple qw(:strict); my $xml = XMLin($tmpfile, ForceArray => 0, SuppressEmpty => 1, KeyAttr + => 'ru_resource' ); my $bandwidth = $xml->{exec_command}->{xml_show_result}->{xml_show_re +source_usage}->{ru_entry}->{bandwidth}->{ru_current}; print $bandwidth;

I get "Use of uninitialized value in print" and don't know why.

The following is the output of Dumper:

$VAR1 = { 'exec_command' => { 'xml_show_result' => { 'xml_show_resource_us +age' => { + 'ru_entry' => { + 'conn ' => { + 'ru_current' => ' 500 +' + }, + 'bandwidth ' => { + 'ru_current' => ' + 2744' + } + } + } }, 'status' => { 'text' => 'XML_CMD_SUCCESS', 'code' => '100' }, 'command' => ' show resource usage context brn0ace01 ' } };

In reply to Issue with using XML::Simple by spawned345

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



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.