[EMAIL PROTECTED] wrote:
> Hi all,

Hello,

> '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";
> }



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>


Reply via email to