in reply to Testing Complex Data Structures

You might want to use XML::Simple's forcearray option for XMLin, which will create an array even when there is only one nested element, thus removing the need for checks.

Replies are listed 'Best First'.
Re: Re: Testing Complex Data Structures
by epoptai (Curate) on Feb 27, 2001 at 16:00 UTC
    The knowledge gained from both tye and btrott's wisdom will surely benefit me in the future, but mirod's offering seems like the right thing to do in this case. I was so focused on the lists it didn't occur to me to go back to XML::Simple's documentation for a way to alter the list. Adding forcearray to XMLin() eliminates the problem.
    my$data = XMLin($url, forcearray => 1);
    Results in the following for a single entry (note the [ and ], they're not present without forcearray):
    $data = { 'foo' => [{ 'one' => '1', 'two' => '2' }] };
    Thank you all!

    Update: I've found that sometimes you also must specify which hash to force by specifying the keyattr.
    my$data = XMLin($url, keyattr => 'foo', forcearray => 1);