Exercises
See Appendix A for the answers to the following exercises:
[25] Make a program that will repeatedly ask the user to guess a secret number from 1 to 100 until the user guesses the secret number. Your program should pick the number at random by using the magical formula
int(1 + rand 100).[†] When the user guesses wrong, the program should respond “Too high” or “Too low.” If the user enters the wordquitorexit, or if the user enters a blank line, the program should quit. Of course, if the user guesses correctly, the program should quit then as well![10] Modify the program from the previous exercise to print extra debugging information as it goes along, such as the secret number it chose. Make your change such that you can turn it off, but your program emits no warnings if you turn it off. If you are using Perl 5.10, use the
//operator. Otherwise, use the ternary operator.[10] Modify the program from Exercise 3 in Chapter 6 (the environment lister) to print
(undefined value)for environment variables without a value. You can set the new environment variables in the program. Ensure that your program reports the right thing for variables with a false value. If you are using Perl 5.10, use the//operator. Otherwise, use the ternary operator.
[†] See what the perlfunc manpage says
about int and rand if you’re curious about these
functions.