
7stud
Enthusiast
May 19, 2010, 3:38 AM
Post #2 of 8
(630 views)
|
|
Re: [ym_chaitu] XML vale fetching
[In reply to]
|
Can't Post
|
|
If you look at the output from Data::Dumper, the email address of each customer is stored in an array. That is what forcearray=>1 does. So, this line $conf->{customer}->{email} returns a reference to an array, and the array contains one email address. So the email address is: $conf->{customer}->{email}->[0]
use strict; use warnings; use 5.010; use XML::Simple qw{ :strict }; my $doc_href = XMLin('xml4.xml', forcearray=>1, KeyAttr=>[]); use Data::Dumper; say Dumper($doc_href); my $customer_aref = $doc_href->{customer}; for my $single_customer_href (@$customer_aref) { my $email = $single_customer_href->{email}->[0]; say $email; } --output:-- $VAR1 = { 'timestamp' => '2002-05-13 15:33:45', 'customer' => [ { 'email' => [ 'joewrigley@jmac.org' ], 'first-name' => [ 'Joe' ], 'address' => [ { 'zip' => [ '82649' ], 'city' => [ 'Meatball' ], 'street' => [ '17 Beable Ave.' ], 'state' => [ 'MI' ] } ], 'age' => [ '42' ], 'surname' => [ 'Wrigley' ] }, { 'email' => [ 'meow@263A.org' ], 'first-name' => [ 'Henrietta' ], 'address' => [ { 'zip' => [ '83642' ], 'city' => [ 'Flangerville' ], 'street' => [ 'R.F.D. 2' ], 'state' => [ 'NY' ] } ], 'age' => [ '37' ], 'surname' => [ 'Pussycat' ] } ], 'version' => '3.5' }; joewrigley@jmac.org meow@263A.org
(This post was edited by 7stud on May 19, 2010, 3:52 AM)
|