in reply to Re^2: XML Parsing,
in thread XML Parsing,
That's odd... when I ran the OP script on the xml file in your reply, I got an error message:
In my copy of the script, line 46 was this one:Not an ARRAY reference at 794307.pl line 46.
Apparently, when the xml file contains only one "Vehicle", the default behavior of XML::Simple is to provide you with something that is not an array reference (e.g. maybe it's a reference to a hash instead of a reference to an array of hashes).foreach $vehicle ( @{ $config->{'Vehicle'} } ) {
That is why moritz, in the first reply, suggested that you include the ForceArray=>1 parameter when you invoke XMLin to create your $config object, like this:
When I made that change and ran it again, I didn't get the error message, and I got more output in addition to just Other Cars<br>.$config = XMLin( $xml, ForceArray => 1, SuppressEmpty => "" );
Anyway, as others have pointed out, there seem to be quite a few points where your code could use some improvement, and where it may even be doing things you don't intend (and/or not doing things you meant to do). Using more data structures, more loops, and better indentation will help a lot.
(updated to fix a mistake in wording)
|
|---|