in reply to XML:Simple Config
If you look at the output of the Dumper, it will tell you how to access the complex structure. Anything that is in curly brackets is a hash and anything in square brackets is an array.
I modified your code as follows:
use strict; use XML::Simple; use Data::Dumper; my $config = XMLin('config.xml'); print Dumper($config); print "$config->{Application}->{Name}\n"; print "$config->{Application}->{Location}->{Name}\n"; print "$config->{Application}->{Location}->{ZDrive}\n"; print "$config->{Application}->{Location}->{CDrive}\n";
In your sample XML file, there's basically 4 pieces of information stored. The last 4 print statements accesses those pieces. Here's the output.
$VAR1 = { 'Application' => { 'Location' => { 'ZDrive' => 'Z:\\Temp', 'CDrive' => 'C:\\Temp', 'Name' => 'Loc1' }, 'Name' => 'App1' } }; App1 Loc1 Z:\Temp C:\Temp
By looking at my modified code and its output, that should help you understand what I'm talking about with using the output from Dumper to decipher the syntax needed to access the complex data structure.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: XML:Simple Config
by PerlScholar (Acolyte) on Sep 02, 2010 at 13:19 UTC | |
by grantm (Parson) on Sep 02, 2010 at 21:45 UTC |