Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Answer
17.1: To repeatedly ask the user for input, wrap my program in a
naked block and use redo to start another go-around when you
finish one round. To break out of the block, you end input with Control D (or
Control Z
on Windows), in which case $string gets
undef and triggers the last function to end the loop.
There are a couple of ways you could handle the possible error from
the user input, and in this answer you’ll use an eval {} block (Answer 17.2 is the same problem with a
different method). The eval will catch the error from an invalid
regular expression. You need a semicolon after the eval {} block because this is a statement,
not a control structure like foreach.
After the eval block, output an error message if
there is something in the eval error variable $@: