A.11 Answer for Chapter 12


A.11.1 Exercise (Section 12.12.1)

The module Oogaboogoo/date.pm looks like this:

 package Oogaboogoo::date; use strict; use Exporter; our @ISA = qw(Exporter); our @EXPORT = qw(day mon); my @day = qw(ark dip wap sen pop sep kir); my @mon = qw(diz pod bod rod sip wax lin sen kun fiz nap dep); sub day {   my $num = shift @_;   die "$num is not a valid day number"     unless $num >= 0 and $num <= 6;   $day[$num]; } sub mon {   my $num = shift @_;   die "$num is not a valid month number"     unless $num >= 0 and $num <= 11;   $mon[$num]; } 1; 

The main program now looks like this:

 use strict; use Oogaboogoo::date qw(day mon); my($sec, $min, $hour, $mday, $mon, $year, $wday) = localtime; my $day_name = day($wday); my $mon_name = mon($mon); $year += 1900; print "Today is $day_name, $mon_name $mday, $year.\n"; 


Learning Perl Objects, References & Modules
Learning Perl Objects, References, and Modules
ISBN: 0596004788
EAN: 2147483647
Year: 2003
Pages: 199

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