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


In reply to Silly While Loop Problems by gsus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.