in reply to refuses to return me 2 values from subroutines
Ah, this is a "fun" list issue :-)
The problem is your use of the || operator. It puts its left hand side in scalar context. The left hand side is the list ($id, $phone). A list in scalar context returns its last element, in this case $phone, which in the calling code gets assigned to $id, and $phone gets nothing (undef). (BTW, you would have come closer to identifying this issue if you had printed $id as well.)
The fix is two parts: change || to the lower-precedence or, and change the return 0 statements in the sub to plain return; statements. The reason for the latter is that in list context, it will return the empty list. If you continued to return 0, then the returned list still has one element, and the error would not be detected.
Of course, another, probably better possibly better fix is to make your code more explicit:
my ($id, $phone) = some_func(); die "oops" unless defined $id; # or whatever the error condition is
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: refuses to return me 2 values from subroutines
by PerlBroker (Acolyte) on Jan 18, 2016 at 14:05 UTC |