$VAR1 = {
'link' => [
{
'rel' => 'alternate',
'href' => 'http://www.test.com'
},
{
'rel' => 'self',
'href' => 'http://www.test.com'
}
],
'xmlns' => 'http://www.w3.org/2005/Atom',
'entry' => {
'number=0001096906-13-000126' => {
'link' => {
'rel' => 'alternate',
'href' => 'http://www.test.com/1',
'type' => 'text/html'
},
'summary' => {
'content' => 'Green',
'type' => 'html'
},
'title' => 'Green Diamond',
'updated' => '2013-02-05T15:34:15-05:00',
'category' => {
'scheme' => 'http://www.test.com/',
}
},
'number=0001096906-13-000130' => {
'link' => {
'rel' => 'alternate',
'href' => 'http://www.test.com/2',
'type' => 'text/html'
},
'summary' => {
'content' => 'Green',
'type' => 'html'
},
'title' => 'Green Diamond',
'updated' => '2013-02-05T15:34:15-05:00',
'category' => {
'scheme' => 'http://www.test.com/',
}
},
'updated' => '2013-02-05T15:38:23-05:00',
'author' => {
'email' => 'webmaster@test.com',
'name' => 'Webmaster'
},
'id' => 'http://www.test.com',
'title' => 'Latest Colors - Tue, 05 Feb 2013 15:38:23 EST'
};
SO far in my code I have….
#!/usr/bin/perl
# use module
use XML::Simple;
use Data::Dumper;
# create object
$xml = new XML::Simple;
# read XML file
$data = $xml->XMLin("sec_rss.xml");
# print output
#print Dumper($data);
foreach $e (@{$data->{entry}[0]}) {
print $e->{link},"\n";
}
But I get confused as to how to iterate over each entry here to grab the elements. Can someone give me a clue to help get me rolling? Many thanks!
First of all, please use
strictandwarningsin your programs. They will help you track down errors.I wasn’t sure what you were struggling with. I’ve commented out part of the XML data structure because I believe something went wrong parsing it or you omitted something. The last part of the
entrykey looks as if there’s another key missing.I’ve then demonstrated how you can look at each entry in turn and access all the information inside it.