sub check_mobiletype { my $destination = shift; if($destination =~ /^\+/ && $destination !~ /^\+{1}.*\D/) { my $id = get_contacts_id_by_mobilephone($destination) or return; my $phone = get_mobilephone($id) or return; return ($id, $phone); } elsif($destination =~ /\d/ && $destination !~ /\D/) { my $id = $destination; my $phone = $tcrm->get_mobilephone($id) or return; return ($id, $phone); } return; } my ($id, $phone) = check_mobiletype($destination) or die "ID not found";
By using or instead of ||, you're checking the result of the assignment (the number of elements returned by its RHS) instead of the result of check_mobiletype. Returning an empty list from check_mobiletype will therefore trigger throwing the exception.
In reply to Re: refuses to return me 2 values from subroutines
by ikegami
in thread refuses to return me 2 values from subroutines
by PerlBroker
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |