I am trying to parse an XML file. The Xml file can be found @ http://pastebin.com/fvuwbrh9.
I have saved this xml file as packages.xml.
Goal: List all the names which are surrounded by <packagereq> tag in the XML (I am referring the packagereq which fall under the group in the dumper output).
I wrote below script called rpm.pl:
#!/usr/bin/perl -w
use strict;
use XML::Simple;
use Data::Dumper;
my $ref = XMLin ('packages.xml');
#print Dumper ($ref);
foreach my $a ( keys %{ $ref->{group} } )
{
if ( exists $ref->{group}->{$a}->{packagelist} )
{
foreach my $b ( @{ $ref->{group}->{$a}->{packagelist}->{packagereq} } )
{
print $b->{content}."\n"; ### <<< referring the Dumper out put
}
}
}
Now my script goes half way throgh and prints the package names but then it gets terminated with below error:
Not an ARRAY reference at rpm.pl line 29.
After above error, the script does not process rest of the XML file and terminates.
Above error makes me believe that somewhere value of $ref->{group}->{$a}->{packagelist}->{packagereq} is not an ARRAY reference.
I have gone as carefuly as I can throguh the XML file (OR the Dumper output) but found that packagereq always points to an ARRAY reference unless and of course I overlooked something but I doubt so.
Could you provide some input on why is it complaining about Not an ARRAY ref.
Thanks.
XML::Simple, the most complicated XML parser to use. Add the following: