J9 has asked for the wisdom of the Perl Monks concerning the following question:
#! perl.exe print "Please enter you name:\n"; chomp ($name =<STDIN>); &answer(); exit; sub answer() { print "Hello $name.\nWill you be joining me for a swim? [Y/N] \n"; chomp ($_=<STDIN>); if (/^[yn]/i) { if (/^n/i) { print "Begone, evil peon!\n" } if (/^y/i) { print "YIPPEEE.!!!!\n"; } } else { # Validate user input and return message if invalid print "\n\n=====================================\n"; print "You Have Entered and Incorrect Option\n"; print "Valid Options are [Y/N]\n"; print "=====================================\n\n"; &answer; } }
My above code also validates Yesterday as true and never as false. I only want to match [Yy]es, [Nn]o or just [Yy] or [Nn].
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Yes No Validation
by chromatic (Archbishop) on Feb 06, 2003 at 18:16 UTC | |
|
Re: Yes No Validation
by lestrrat (Deacon) on Feb 06, 2003 at 18:18 UTC | |
|
Re: Yes No Validation
by steves (Curate) on Feb 06, 2003 at 18:19 UTC | |
by LAI (Hermit) on Feb 06, 2003 at 20:52 UTC | |
|
Re: Yes No Validation
by Three (Pilgrim) on Feb 07, 2003 at 14:28 UTC |