Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^3: XML Parsing,

by graff (Chancellor)
on Sep 09, 2009 at 23:14 UTC ( [id://794471]=note: print w/replies, xml ) Need Help??


in reply to Re^2: XML Parsing,
in thread XML Parsing,

the script stops. it doesn't give an error. ...

That's odd... when I ran the OP script on the xml file in your reply, I got an error message:

Not an ARRAY reference at 794307.pl line 46.
In my copy of the script, line 46 was this one:
foreach $vehicle ( @{ $config->{'Vehicle'} } ) {
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).

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:

$config = XMLin( $xml, ForceArray => 1, SuppressEmpty => "" );
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>.

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)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://794471]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-03-29 06:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found