in reply to How to restrict the user to enter only 1 character

Actually, I think it would be more intuitive to allow them to type 'y', 'n', 'yes', 'no', 'Yes', or 'No' and simply test the first character.

my $answer = <STDIN>; my $first_char = substr $answer, 0, 1; if ( lc $first_char eq 'y' ) { # they answered 'yes' } else { # they answered something else }

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Replies are listed 'Best First'.
Re: (Ovid) Re: How to restrict the user to enter only 1 character
by dmmiller2k (Chaplain) on Oct 30, 2001 at 03:05 UTC

    Yes, but that would require also pressing Return, which, if I am reading the question right, may not be what the original poster wanted.

    (Actually, I am projecting what I meant, when I myself--oh so many moons ago--asked pretty much the same thing on some forum or another.)

    dmm

    
    You can give a man a fish and feed him for a day ...
    Or, you can teach him to fish and feed him for a lifetime