use Term::ReadKey; sub Request($;$$) { chomp(my $talk = shift || return -1); #required arg, the question! chomp(my $letters = shift || "Ny"); #letters to display chomp(my $return = shift || 1); #do you need a line break after the anwser is given my $answer; { $answer = undef; #set to null print "$talk? [$letters] "; #note a '?' is given ReadMode('cbreak'); #ReadKey is here 'cause I just like to use it. $answer = ReadKey(0);#quick! ReadMode('normal'); chomp $answer; #I always chomp my vars. Even if Gram gave them to me. if(!(grep /$answer/i, $letters)) #not a real choice { print "\nplease answer [$letters]\n"; redo } } if($return){print "\n"}#the newline bump return $answer; #I tend to use it like this #if((Request("Setup metacheck.sh in crontab", "Ny")) =~/Y/i){yak;yak;y +ak;} }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: questions, questions
by Aristotle (Chancellor) on Sep 19, 2002 at 19:32 UTC | |
by halxd2 (Monk) on Sep 19, 2002 at 20:38 UTC | |
by Aristotle (Chancellor) on Sep 19, 2002 at 20:42 UTC |