tryingnottofailmytes has asked for the wisdom of the Perl Monks concerning the following question:
I really can't figure out why the loop isn't running......I know the answer is simple but I just can't figure it out.my $messagetouser= "What is your favorite Color?"; my $ans = tryagain5 ( $messagetouser ); if ($ans) { print "$ans\n"; } else { print "You didn't reply! Goodbye.\n"; exit; } #print $answer, "\n"; sub callandresponse { my ($messagetouser)=@_; print $messagetouser,"\n"; my $ans=<STDIN>; chomp $ans; return $ans; } sub tryagain5 { my($messagetouser)=@_; my $ans = callandresponse ($messagetouser); my $count=1; while ($count < 5 and $ans =~ /^\s*\n/) { $count++; $ans = callandresponse ($messagetouser); } if ($ans =~ /^\s*\n/) { return 0; } else { return $ans;} }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Subroutine Loop
by poj (Abbot) on Dec 06, 2015 at 16:39 UTC | |
|
Re: Subroutine Loop
by james28909 (Deacon) on Dec 06, 2015 at 16:58 UTC | |
|
Re: Subroutine Loop
by Anonymous Monk on Dec 06, 2015 at 16:58 UTC | |
|
Re: Subroutine Loop
by QuillMeantTen (Friar) on Dec 06, 2015 at 16:59 UTC | |
by tryingnottofailmytes (Novice) on Dec 06, 2015 at 18:32 UTC |