my %is_legal = map { $_ => 1 } qw( y yes n no ); my $answer; { print "What is your answer? "; chomp( $answer = <> ); $answer = lc $answer; last if $is_legal{ $answer }; redo; } # Do something with $answer, which is now guaranteed to be 'y', 'yes', + 'n', or 'no'
------
We are the carpenters and bricklayers of the Information Age.
Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose
I shouldn't have to say this, but any code, unless otherwise stated, is untested
In reply to Re: Useful uses of redo?
by dragonchild
in thread Useful uses of redo?
by kvale
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |