I began a similar thread on this topic, but this seems more to be a fundamental lack of understanding of arrays in Perl. It has me more than scratching my head. I've read through the perldocs and am missing something.

I've never pretended to be a great Perl programmer, but I really shouldn't be falling down on points like this. After 6 or 7 years of this, you'd think I'd actually know something. Maybe I should take up singing in a punk band.

Could someone direct me to documentation that will help me understand how to solve the following ...

The code:
#!/usr/bin/perl -w use XML::Simple; # qw(:strict); my $ref = XMLin("xmlTest3.xml", forcearray=>1, keyattr=>{wrapper=>"nam +e"}); my $wrapName = "testName 1.0.3"; print "$ref->{wrapper}->{$wrapName}->{script}\n"; print "$ref->{wrapper}->{$wrapName}->{envVar}->[0]->{value}\n"; # How do I enumerate the contents of the tags such as envVar and parm? # The following only gives me an address to the array. foreach my $pName ($ref->{wrapper}->{$wrapName}->{envVar}) { print $pName; }
The data:
<config> <wrapper name="testName 1.0.3" script="/usr/people/ltorvalds/wrapp +er.pl" app="/usr/bin/testApp.exe"> <envVar name="TMPDIR" value="/usr/tmp"/> <envVar name="TEMPDIR" value="/usr/tmp"/> <parm name="pad" value="4"/> <parm name="me" value="0"/> <parm name="mf" value="0"/> <parm name="s" value="\$startFrame"/> <parm name="e" value="\$endFrame"/> <parm name="b" value="\$byFrame"/> <parm name="im" value="\$cacheDir\$qmJob.\$suffix"/> <parm name="of" value="\$fileExt"/> </wrapper> <wrapper name="testName2" script="/usr/people/wgates/wrapper2.pl" +engine="/usr/bin/testApp2.exe"> <envVar name="MAYA_LOCATION" value="\$appPath"/> <envVar name="MAYA_SCRIPT_PATH" value="/data/render_common/scr +ipts"/> <envVar name="TMPDIR" value="/usr/tmp"/> <envVar name="TEMPDIR" value="/usr/tmp"/> <parm name="pad" value="4"/> <parm name="me" value="0"/> <parm name="mf" value="0"/> <parm name="s" value="\$startFrame"/> <parm name="e" value="\$endFrame"/> <parm name="b" value="\$byFrame"/> <parm name="im" value="\$cacheDir\$qmJob.\$suffix"/> <parm name="of" value="\$fileExt"/> </wrapper> </config>
Thanks for any input.

In reply to How to access data from arrays with XML::Simple by ccarden

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.