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
.



Relevant Pages

  • Re: "Cant return a temporary from lvalue subroutine..."
    ... >>hash value to a scalar. ... > statement of the method are ignored when it is used as an lvalue. ... >>returned a reference to a tied hash in response to %{$obj}, ...
    (comp.lang.perl.misc)
  • Re: Help with tied/nested data structures
    ... had a plain hash that had a few scalars inside of it that were tied. ... After I tie the scalar, it nearly gets immediately culled by the Perl ... the hash-tying mechanism itself. ...
    (comp.lang.perl.misc)
  • weird behavior when passing hashes to subroutine
    ... I was working on a program today and made a sub routine that I ... was passing a few scalars and also a hash to as arguments. ... my $bar = 'soda is yummy!'; ... and found that if I reverse the order so the scalar is passed before ...
    (comp.lang.perl.misc)
  • Re: Help with tied/nested data structures
    ... survives, the object survives. ... when %hash itself it tied. ... Scalar tie() only works on actual scalar ...
    (comp.lang.perl.misc)
  • Re: Dealing with a STRANGE API
    ... hash element error message). ... I tried obvious things like setting a scalar to the result ...
    (comp.lang.perl.misc)