John W. Krahn wrote:
> [EMAIL PROTECTED] wrote:
>
>>'m trying to parse a simple xml document as below..
>>
>>--------
>>
>>#!/usr/bin/perl -w
>>use strict;
>># use module
>>
>>use XML::Simple;
>>use Data::Dumper;
>>
>># create object
>>my $config = XMLin('data.xml');
>>
>># print output
>>#print Dumper($config);
>>
>># access XML data
>>foreach $e (@{$config->{employee}})
>
> $config->{employee} is a reference to a hash, not an array, so change that to:
>
> for my $e ( values %{$config->{employee}} )
>
>
>>{
>> print $e->{name}, "\n";
>> print "Age/Sex: ", $e->{age}, "/", $e->{sex}, "\n";
>> print "Department: ", $e->{department}, "\n";
>> print "\n";
>>}
I tried it out and you need a for loop like this:
for my $name ( keys %{$config->{employee}} ){
print "$name\n";
print "Age/Sex:
$config->{employee}{$name}{age}/$config->{employee}{$name}{sex}\n";
print "Department: $config->{employee}{$name}{department}\n";
print "\n";
}
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>