Keep It Simple, Stupid | |
PerlMonks |
Check if XML element existsby johnfl68 (Scribe) |
on Mar 26, 2013 at 00:58 UTC ( [id://1025422]=perlquestion: print w/replies, xml ) | Need Help?? |
johnfl68 has asked for the wisdom of the Perl Monks concerning the following question: Hello: I thought I had this figured out once before, but now it's not coming to me (or at least not quit right). I always seem to have troubles with the whole hash/array thing as my brain always seems to interpret it differently than it is. I have a XML file, some of the data entries have 'codeshares' elements, and some do not. Some have only 1 and others may have 2 or 3. I am using XML::Simple because is works for 98% of what I need. I have tried using the following in hopes to get a number response back based on the number of codeshares entries: my $codeshares = scalar @{$database->{'flightStatuses'}->{'flightStatus'}->[$loop]->{'codeshares'}->{'codeshare'}};And a XML Sample:
But if it is less than 2 codeshares, I get "Not an ARRAY reference at..." back. If I have 2 or more codeshares it seems to work fine. Anyone know what I might possibly be missing, or is there another way to find out (in this case) how may codeshares there are, so I can read them? Everything else I have so far works fine. Thanks as always! John
Back to
Seekers of Perl Wisdom
|
|