Re: Dealing with a STRANGE API



Ignoramus7272 <ignoramus7272@xxxxxxxxxxxxxxxxxxx> wrote in comp.lang.perl.misc:
I am using PayPal API class

Business::PayPal::API::TransactionSearch

It uses some very weird code

Indeed. Snipped.

that is, it returns a hash when there is error, and a list reference
when there is not.

I am bewildered, just how can I get this result into one variable and
then figure out if I am dealing with success (so that I can print
results from the list reference), or failure (so that I can print a
hash element error message).

Any idea? I tried obvious things like setting a scalar to the result
of this function, and could not.

Untested:

my @mystery = $obj->meth_from_hell( ...);

if ( @mystery == 1 ) {
my @array = @{ $mystery[ 0] };
# normal processing
} else {
my %hash = @mystery;
# error
}

The distinction is reliable because the hash returns an even number of
scalars.

You shouldn't have to do this.

Anno
.