here's the basic code that i'm starting with:
- Code: Select all
use XML::Simple;
use Data::Dumper;
$xml = XML::Simple->new (ForceArray => 1);
$data = $xml->XMLin("blog.xml");
print "$data->{entry}->[0]->{id}\n";
Here's a simplified blog.xml file I'm testing with:
- Code: Select all
<?xml version='1.0'?>
<feed>
<id>11235813</id>
<author>
<name>myrcutio</name>
<email>foo@fum.com</email>
</author>
<entry>
<id>2</id>
<postdate>1854-12-09T09:50:27</postdate>
<title>Balaclava Sundae</title>
<content>Storm'd at with shot and shell</content>
</entry>
<entry>
<id>1</id>
<postdate>1854-12-09T08:47:35</postdate>
<title>Crimean Pentathlon</title>
<content>Boldly they rode and well</content>
</entry>
</feed>
The xml I'll actually be parsing is pretty large though; it's a few years worth of blog entries. The structure is the same though.
I can read in the base elements just fine using $data->{id}; or $data->{author}->{name}; but it seems to nest all the <entry> elements in a single nested hash. I don't really understand what it's doing at that point, it seems like it should just make a hash array with each array element one of the <entry> objects, and I do get an array when I try print $data->{entry};
but if I try the following it only returns a single hash:
- Code: Select all
@entries = $data->{entry};
print @entries;
What should I do?
