in reply to Re^2: unexpected STDIN
in thread unexpected STDIN
and it doesn't work for my "neVer" answerYes, it does: $answer =~ m/^v|(?:never)$/i
If you are using a relatively modern Perl (5:10 or later) you can even use the Perl switch construct (which is called given ... when).
use Modern::Perl; my $answer = <STDIN>; given ($answer) { when (/^y(?:es)?$/i) { say 'yes'; } when (/^no?$/i) { say 'no'; } when (/^a(?:ll)?$/i) { say 'all'; } when (/^v|(?:never)$/i) { say 'never'; } default { say 'default'; } }
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
|
|---|