ccarden has asked for the wisdom of the Perl Monks concerning the following question:
The following code successfully parses the xml file:<config> <wrapper name="testName 1.0.3" script="/usr/people/ltorvalds/apps/ +wrapper.pl" app="testApp.exe"> <envVar name="TMPDIR" value="/usr/tmp"/> <envVar name="APPDIR" value="/usr/bin"/> </wrapper> </config>
... and correctly produces the following output ...#!/usr/bin/perl -w use XML::Simple; my $ref = XMLin(); my $wrapName = "testName 1.0.3"; print "$ref->{wrapper}->{$wrapName}->{script}\n"; print "$ref->{wrapper}->{$wrapName}->{envVar}->{TMPDIR}->{value}\n";
Now, if I try to treat the <envVar> tags as an array, I run into trouble:/usr/people/ltorvalds/wrapper.pl /usr/tmp
... produces a blank line. I assumed that this was because I needed to turn forceArray on, so I changed the call to XMLin():print "$ref->{wrapper}->{$wrapName}->{envVar}->[0]->{value}\n";
... but still I get the same blank line as output.my $ref = XMLin(xmlTest.xml, forceArray=>['envVar']);
I suspect that I'm either using forceArray incorrectly or I'm using an invalid array reference. Any insight as to where my folly lies would be appreciated.
Thanks for all of the input. What have I learned? I have learned that I need to:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How do I correctly use arrays with XML::Simple?
by mirod (Canon) on Oct 08, 2003 at 16:09 UTC | |
|
Re: How do I correctly use arrays with XML::Simple?
by EdwardG (Vicar) on Oct 08, 2003 at 16:04 UTC | |
|
Re: How do I correctly use arrays with XML::Simple?
by grantm (Parson) on Oct 08, 2003 at 18:16 UTC | |
|
Re: How do I correctly use arrays with XML::Simple?
by eric256 (Parson) on Oct 08, 2003 at 15:52 UTC |