Section 14.7. Exercises


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?




Intermediate Perl
Intermediate Perl
ISBN: 0596102062
EAN: 2147483647
Year: N/A
Pages: 238

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net