Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: prompting a user for input

by perigeeV (Hermit)
on Nov 04, 2001 at 17:50 UTC ( #123183=note: print w/replies, xml ) Need Help??


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(); }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://123183]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2022-11-30 21:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?