Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: refuses to return me 2 values from subroutines

by ikegami (Patriarch)
on Jan 18, 2016 at 14:29 UTC ( [id://1153025]=note: print w/replies, xml ) Need Help??


in reply to refuses to return me 2 values from subroutines

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1153025]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2024-04-24 10:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found