in reply to Perl & Simple::XML

I expect your problem is a quirk with XML::Simple. If there is just one author in your AuthorList, XML::Simple turns it into a hash something like this
{AuthorList => {CompleteYN=>"Y", Author => {ValidYN=>"Y", LastName=>"Dinos", ForeName=>"A E"}}}
but if there's more than one author, XML::Simple puts in an array ref.
{AuthorList => {CompleteYN=>"Y", Author => [{ValidYN=>"Y", LastName=>"Tsirgos", ForeName=>"K T"}, {ValidYN=>"Y", LastName=>"Dinos", ForeName=>"A E"}]}}
Use the 'ForceArray' option on XMLin so that author always gets the array ref. That way your code doesn't choke on one case or the other.

The notes to XML::Simple say that they wish they'd made ForceArray the default. I guess there's too much established code out there to change the default now.

Read up on it. BTW, while you're there, read about KeyAttr, too. You'll want to use it.

throop

Replies are listed 'Best First'.
Re^2: Perl & Simple::XML
by Jenda (Abbot) on Oct 07, 2007 at 10:19 UTC

    Making it a default for all tags, including those that are no allowed to be repeated in the XML would cause the resulting data structure to be overly complex and hard to navigate. You would not want to have to write $data->{foo}[0]{bar}[0]{baz}[0] instead of $data->{foo}{bar}{baz}, especially if you knew for sure non of the tags in question can ever be repeated.

    Do use ForceArray, but only use it for the tags that can be repeated. And there, us it for all such tags.