in reply to prompting a user for input
Here's some fun; reverse the string and the regex in the statement, eg.:
if ( "" =~ /^\Q$answer/i ) { default() } elsif( "YES" =~ /^\Q$answer/i ) { affirmative() } elsif( "NO" =~ /^\Q$answer/i ) { negative() }
Now the user can type "y", "ye" or "yes".
Or if you want you can build a case statement:
SWITCH: { $answer =~ /^yes|y$/ && do { affirmative(); last SWITCH; }; $answer =~ /^no|n$/ && do { negative(); last SWITCH; }; default(); }
|
---|
In Section
Seekers of Perl Wisdom