PerlBroker has asked for the wisdom of the Perl Monks concerning the following question:
This is SSCCE example code. At the position (A) in the code, I am asking subroutine check_mobiletype to find the ID, and phone number. It does find the ID and phone, at position (B). I don't know why, but at position (C) it says: "Use of uninitialized value $phone in say"...
So, I get kind of dizzy feeling, and trying to find a solution.
#!/usr/bin/perl my $destination = '+123'; if($destination eq 'show') { $show = 1; $destination = shift @ARGV; utf8::decode($destination); $sms = join(" ", @ARGV); # POSITION (A) my ($id, $phone) = check_mobiletype($destination) || die "ID not f +ound"; # POSITION (C) print $id, $phone, "\n"; # ID is not printed } else { $sms = join(" ", @ARGV); die "No text" unless $sms; my ($id, $phone) = check_mobiletype($destination) || die "ID not f +ound"; print $id, ' ', $phone, "\n"; } exit; sub check_mobiletype { my $destination = shift; if($destination =~ /^\+/ && $destination !~ /^\+{1}.*\D/) { print "Type phone number\n"; my $id = get_contacts_id_by_mobilephone($destination) || retur +n 0; my $phone = get_mobilephone($id) || return 0; # POSITION (B) print $id, ' ', $phone, "\n"; # ID and phone are printed return ($id, $phone); } elsif($destination =~ /\d/ && $destination !~ /\D/) { #say "Type ID"; my $id = $destination; my $phone = $tcrm->get_mobilephone($id) || return 0; return ($id, $phone); } } sub get_mobilephone { return '+49121212121'; } sub get_contacts_id_by_mobilephone { return 123456; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: refuses to return me 2 values from subroutines
by ikegami (Patriarch) on Jan 18, 2016 at 14:29 UTC | |
|
Re: refuses to return me 2 values from subroutines
by Anonymous Monk on Jan 18, 2016 at 13:57 UTC | |
by PerlBroker (Acolyte) on Jan 18, 2016 at 14:05 UTC |