If you look at $data for the problem file its not an array at that point. For a single element XML::Simple doesn't display your data in a list i.e.
With 1 element of record. $VAR1 = { 'RECORD' => { 'COLLNAME' => 'FBIS2004', 'DOCI' => 'CP1' } }; With 2 elements of record. $VAR1 = { 'RECORD' => [ { 'COLLNAME' => 'FBIS2004', 'DOCI' => 'CP1' }, ' BOOB' ] }; So you cant do @{$data->{RECORD}} as it doesn't exist when there is only 1 element. You can either test that its an arrayref or hashref or you could use something like XML::Parser, Lib:XML Etc... -----Original Message----- From: Dave Adams [mailto:[EMAIL PROTECTED] Sent: 02 April 2007 15:15 To: beginners perl Subject: Not an ARRAY reference. Problems reading a simple XML file My script is having problems reading and XML file with only one record in it. When I add two or more records, there are no problems. The error is "Not and ARRAY reference.." Here is the PROBLEM xml file (test.xml): <?xml version="1.0" encoding="ISO-8859-1" ?> <DATA> <RECORD> <COLLNAME>FBIS2004</COLLNAME> <DOCI>CP1</DOCI> </RECORD> </DATA> Here is the WORKING xml file: <?xml version="1.0" encoding="ISO-8859-1" ?> <DATA> <RECORD> <COLLNAME>FBIS2004</COLLNAME> <DOCI>CP1</DOCI> </RECORD> <RECORD> <COLLNAME>FBIS2005</COLLNAME> <DOCI>CP2</DOCI> </RECORD> </DATA> Here is my script: #!/usr/bin/perl use XML::Simple; use Data::Dumper; $xml = new XML::Simple (KeyAttr=>[]); $data = $xml->XMLin("test.xml"); #print Dumper($data); print "There are " . scalar(@{$data->{RECORD}}) . " records.\n"; foreach my $var (@{$data->{RECORD}}) { print $var->{DOCI} . "\n"; print $var->{COLLNAME} . "\n"; } Does anyone have an explaination for this? Thanks in advance, DA This e-mail is from the PA Group. For more information, see www.thepagroup.com. This e-mail may contain confidential information. Only the addressee is permitted to read, copy, distribute or otherwise use this email or any attachments. If you have received it in error, please contact the sender immediately. Any opinion expressed in this e-mail is personal to the sender and may not reflect the opinion of the PA Group. Any e-mail reply to this address may be subject to interception or monitoring for operational reasons or for lawful business practices. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/