Приглашаем посетить
Набоков (nabokov-lit.ru)

Section 14.7.  Exercises

Previous
Table of Contents
Next

14.7. Exercises

You can find the answers to these exercises in "Answers for Chapter 14" in the Appendix.

14.7.1. Exercise 1 [20 min]

Write a module named MyDate that has an AUTOLOAD method that handles the calls to the methods named day, month, and year, returning the appropriate value for each one. For any other method, the AUTOLOAD should carp about the unknown method name. Write a script that uses your module and prints the values for the date, month, and year.

14.7.2. Exercise 2 [40 min]

Starting with the script you wrote for the previous exercise, add a UNIVERSAL::debug function that prints a timestamp before the message you pass to it. Call the debug method on the MyDate object. What happens? How does this get around the AUTOLOAD mechanism?


Previous
Table of Contents
Next