Greetings Great Perl Monks. Just starting to use XML::Simple. Does a good job. Very simply , the code bombs out and doesnt print in the test foreach loop. I forced the output into a scalar array and still Bombs. This should have fixed it. Heres what in the input file.
<?xml version="1.0" encoding="ISO-8859-1" ?> <rss version="2.0"> <channel> <title>Used Cars fl</title> <link>http://usedcars.com</link> <language>en-us</language> <lastBuildDate>Thu, 14 Jun 2012 13:00:00 -0400</lastBuildDate> <copyright>Copyright 2012, West Palm Beach</copyright> <ttl>120</ttl> <item> <title><![CDATA[220 Used Cars]]></title> <pubDate>Wed, 16 May 2012 20:14:52 -0400</pubDate> <link>http://usedcars.com</link> <guid>http://usedcars.com</guid> <description>Description of used car.</description> </item> </channel> </rss> ******************************************************* Perl Code: use CGI qw/:standard/; use LWP::UserAgent; use XML::Simple; $XML::Simple::PREFERRED_PARSER = 'XML::Parser'; use Data::Dumper; $page=new CGI; use CGI::Carp 'fatalsToBrowser'; print $page->header; $xml = new XML::Simple (KeyAttr=>[''],NSExpand => 0,ForceArray=> 1); # read XML file $html="data_records2.txt"; $data =$xml->XMLin($html); open(FILE1,">data_out.txt"); print FILE1 Dumper($data); #if ($@) { warn "Error: $@\n"; #} $config_string='{channel}{item}'; foreach $e(@{eval("\$data->$config_string")}) { $count++; print $e->{title} ,$e->{description}, $e->{link}."\n"; } close(FILE1); exit; ############################################ Heres the output . Never gets to print data in the foreach loop. $VAR1 = { 'version' => '2.0', 'channel' => [ { 'link' => [ 'http://usedcars.com' ], 'lastBuildDate' => [ 'Thu, 14 Jun 2012 13:00:00 + -0400' ], 'language' => [ 'en-us' ], 'ttl' => [ '120' ], 'item' => [ { 'link' => [ 'http://usedcars.com' ], 'guid' => [ 'http://usedcars.com' ], 'title' => [ '220 Used Cars' ], 'description' => [ 'Description of +used car.' ], 'pubDate' => [ 'Wed, 16 May 2012 20 +:14:52 -0400' ] } ], 'copyright' => [ 'Copyright 2012, West Palm Bea +ch' ], 'title' => [ 'Used Cars fl' ] } ] }; ****************************************************** Thanks you Oh mighty perl Gods--- I mean Monks. This appears too ez. I + hang my head low in light of the great ones.

In reply to XML::Simple Array bombs out with 1 Item in document by roncoe2000

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.