ranjan_jajodia has asked for the wisdom of the Perl Monks concerning the following question:
<opt> <person firstname="Joe" lastname="Smith"> <email>joe@smith.com</email> <email>jsmith@yahoo.com</email> </person> <person firstname="Bob" lastname="Smith"> <email>bob@smith.com</email> </person> </opt>
On running I always get the size as 1. I think the way I am trying to get the size is wrong because in order to get the person blocks I need to do $config->{person}->[0] etc. instead of $config->{person}[0]. I admit I have not used hashes earlier but I did try keys function on $config->{person} which gives "Type of arg 1 to keys must be hash (not hash element)" error. Could anyone please tell me the right way to loop through the elements?use XML::Simple; use strict; use Data::Dumper; my $config = XMLin("testFile.xml",forcearray => ['person','email']); my @persons = $config->{person}; print "Size:".@persons;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Looping through nested repeated elements using XML::Simple
by ikegami (Patriarch) on Dec 13, 2006 at 06:50 UTC | |
by ranjan_jajodia (Monk) on Dec 13, 2006 at 07:17 UTC | |
|
Re: Looping through nested repeated elements using XML::Simple
by pemungkah (Priest) on Dec 13, 2006 at 07:02 UTC | |
by ranjan_jajodia (Monk) on Dec 13, 2006 at 07:20 UTC | |
by pemungkah (Priest) on Dec 13, 2006 at 20:11 UTC |