gsus has asked for the wisdom of the Perl Monks concerning the following question:
Evening Perl Monks
I have a really simple requirement on a project that i'm working on at home which requires what i believe is a while loop. In it's most simple form, i want to prompt a user running a script to enter either Y or N to continue or abort the script.
Below is what i thought might work, oh and i have this in a subroutine.
sub continue_yn { print "Do you wish to continue the installation (Y/N) : "; $yn=<STDIN>; while (lc($yn) ne "y" || lc($yn) ne "n") { print "Invalid option, please enter an Y or N : "; $yn=<STDIN>; } print "Valid option entered"; }
When my program calls this sub routine, no matter what i enter in for the variable $yn it never tests TRUE in the while loop and just continues to prompt me with my Invalid Option message.
Sorry i should have mentioned that once i've gone through the loop i'll have an if statement to either exit and abort the program or just drop out of the sub routine and continue processing.
Thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Silly While Loop Problems
by MidLifeXis (Monsignor) on Sep 30, 2011 at 17:52 UTC | |
by gsus (Initiate) on Sep 30, 2011 at 17:56 UTC | |
|
Re: Silly While Loop Problems
by blue_cowdawg (Monsignor) on Sep 30, 2011 at 17:43 UTC | |
|
Re: Silly While Loop Problems
by roboticus (Chancellor) on Sep 30, 2011 at 17:44 UTC | |
by Anonymous Monk on Sep 30, 2011 at 17:52 UTC | |
by SuicideJunkie (Vicar) on Sep 30, 2011 at 18:20 UTC | |
by ikegami (Patriarch) on Oct 01, 2011 at 00:30 UTC | |
by ikegami (Patriarch) on Oct 01, 2011 at 00:31 UTC | |
|
Re: Silly While Loop Problems
by hbm (Hermit) on Sep 30, 2011 at 19:09 UTC | |
|
Re: Silly While Loop Problems
by TomDLux (Vicar) on Sep 30, 2011 at 18:24 UTC | |
|
Re: Silly While Loop Problems
by Marshall (Canon) on Oct 01, 2011 at 12:34 UTC | |
|
Re: Silly While Loop Problems
by OfficeLinebacker (Chaplain) on Sep 30, 2011 at 17:49 UTC |