Data::Dumper is your friend here.
I have modified your code slightly to include some diagnostics:
Code:
use strict;
use warnings;
use XML::Simple;
use Data::Dumper;
my $LibList = XMLin('.\\library.xml', forcearray=>1, keyattr => ['id']);
print Dumper($LibList);
my $name = $LibList->{'1'}->{name};
print "Customer id " . $name . "\n";
And the structure of your $LibList appears to be:
Code:
$VAR1 = {
'book' => {
'ARRAY(0x238870c)' => {
'name' => [
'ABCDEF'
]
},
'ARRAY(0x238864c)' => {
'name' => [
'ABC'
]
},
'ARRAY(0x23886ac)' => {
'name' => [
'ABC123'
]
}
}
};
I would suggest removing the 'forcearray' paramater, so that your data ends up looking like this:
Code:
$VAR1 = {
'book' => {
'1' => {
'name' => 'ABC'
},
'2' => {
'name' => 'ABC123'
},
'3' => {
'name' => 'ABCDEF'
}
}
};
And then your code becomes:
Code:
use strict;
use warnings;
use XML::Simple;
use Data::Dumper;
my $LibList = XMLin('.\\library.xml', keyattr => ['id']);
print Dumper($LibList);
my $name=$LibList->{'book'}->{'1'}->{'name'};
print "Customer id " . $name . "\n";