This section provides a tutorial sample Perl module, CalendarModule.pm, which hold some calendar elements of the current date and time. It also provides a subroutine, isLeapYear().
I think I am ready to write simple modules now. Here is one that provides calendar
elements as scalars, and offers one subroutine to determine if the current year is
a leap year:
#- CalendarModule.pm
#- Copyright (c) 1995 by Dr. Herong Yang, http://www.herongyang.com/
#
package CalendarModule;
sub BEGIN {
$author = "Dr. Herong Yang";
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$b) = localtime();
($swday,$smon,$smday,$stime,$syear) = split(' ',localtime());
}
sub isLeapYear {
local $day59 = time() - ($yday-59)*24*60*60;
local ($0,$1,$2,$3,$m,$5,$6,$7,$8) = localtime($day59);
$m = 0 unless $m==1;
return $m;
}
1;