D
Derek Basch
I am newer to Perl and am trying to fix someone elses code so I need
some help. When a subroutine returns a hash reference how can you test
for failure of the called subroutine?
For instance if the "pfp_transaction" subroutine fails it will return
scalar 0. Then the interpreter will complain that 0 is a bad hash
reference when it is dereferenced within the "test" subroutine.
sub test {
# bill card
my %ccresult = %{$self->bill_card($ccnum, $ccexp, $amount, $uid)};
}
sub bill_card {
my %ccresult = $self->pfp_transaction(@order_data) || return 0);
return \%ccresult;
}
It seems like it is a very bad idea to use a subroutines return scalar
as a hash dereference because you can't return 0 for error conditions.
Am I correct?
Thanks All,
Derek Basch
some help. When a subroutine returns a hash reference how can you test
for failure of the called subroutine?
For instance if the "pfp_transaction" subroutine fails it will return
scalar 0. Then the interpreter will complain that 0 is a bad hash
reference when it is dereferenced within the "test" subroutine.
sub test {
# bill card
my %ccresult = %{$self->bill_card($ccnum, $ccexp, $amount, $uid)};
}
sub bill_card {
my %ccresult = $self->pfp_transaction(@order_data) || return 0);
return \%ccresult;
}
It seems like it is a very bad idea to use a subroutines return scalar
as a hash dereference because you can't return 0 for error conditions.
Am I correct?
Thanks All,
Derek Basch