Section 10.10. Exercises


10.10. Exercises

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

10.10.1. Exercise 1 [25 min]

The Oogaboogoo natives on the island have unusual names for the days and months. Here is some simple but not very well-written code from Gilligan. Fix it up, add a conversion function for the month names, and make the whole thing into a library. For extra credit, add suitable error checking and consider what should be in the documentation.

 @day = qw(ark dip wap sen pop sep kir); sub number_to_day_name { my $num = shift @_; $day[$num]; } @month = qw(diz pod bod rod sip wax lin sen kun fiz nap dep); 

10.10.2. Exercise 2 [15 min]

Make a program that uses your library and the following code to print out a message, such as Today is dip, sen 15, 2011, meaning that today is a Monday in August. (Hint: the year and month numbers returned by localtime may not be what you'd expect, so you need to check the documentation.)

 my($sec, $min, $hour, $mday, $mon, $year, $wday) = localtime; 




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