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;} }
In reply to questions, questions by halxd2
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |