Returning array references with only one entry

Posted on 2009-11-19 05:08:42-08 by mbrf
Returning array references with only one entry
Hi all, I have several complex types which are added as ARRAY references to the main data %hash. If there is only one entry, not several, perl internally uses only a HASH, not an array, and the generated XML looks different. Without this code here I get perl errors in the client like "Not an ARRAY reference at" ... Any elegant ways to solve this so I could skip thoses checks ? Other SOAP-Kits contain options like "forcearray = 1" to force this.
my $type = ref( $response->{'List'} ); if ($type eq "ARRAY") { foreach my $userentry (@{$response->{'List'}}) { $user = $userentry->{'Item'}->{'User'}; [...] } else { $user = $response->{List}->{'Item'}->{'User'}; [...] }
-- Martin
Direct Responses: 11783 | Write a response