Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

II. Answers > Q. Answers to Chapter 17 Exercises

Appendix Q. Answers to Chapter 17 Exercises

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 $@:


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial