精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>编程开发>>● CGI>>实例分析>>用perl写的月历(源代码)

主题:用perl写的月历(源代码)
发信人: jaron()
整理人: workingnow(2002-09-30 12:01:16), 站内信件
#!/usr/bin/perl
$|=1;
print "Content-type: text/html\n\n";
&small_calendar(6,2001); # 要显示的月份
sub small_calendar {
$month = shift;
$year = shift;
&PerpetualCalendar($month,1,$year);
$start_day = $perp_dow;
$days_in_month = $perp_eom;
$curr_day = 0;
$return = qq|<TABLE BORDER=1 CELLPADDING=0 cellspacing=0 BGCOLOR=white>
<TR><TD COLSPAN=7 VALIGN=TOP ALIGN=CENTER>
$year年$month月</TD></TR><tr><td>日</td><td>一</td><td>二</td><td>三</td><td>四</td><td>五</td><td>六</td></tr>|;
foreach $date (1-$start_day .. $days_in_month) {
if ($curr_day == 0) { $return .= "<TR>"; }
if ($date > 0) {
$return .= "<TD VALIGN=TOP>$date</TD>";
}
else {
$return .= "<TD></TD>";
}
$curr_day++;
if ($curr_day == 7) {
$return .= "</TR>\n";
$curr_day=0;
}
}
$return .= "</TABLE>\n";
print $return;
} #end of small_calendar

sub PerpetualCalendar {
($perp_mon,$perp_day,$perp_year) = @_;
%day_counts =
  (1,0,2,31,3,59,4,90,5,120,6,151,7,181,
  8,212,9,243,10,273,11,304,12,334);
$perp_days = (($perp_year-1601)*365)+(int(($perp_year-1601)/4));
$perp_days += $day_counts{$perp_mon};
$perp_days += $perp_day;
$perp_sofar = $day_counts{$perp_mon};
$perp_sofar += $perp_day;
$perp_togo = 365-$perp_sofar;
if (int(($perp_year-1600)/4) eq (($perp_year-1600)/4)) {
$perp_togo++;
if ($perp_mon > 2) {
$perp_days++;
$perp_sofar++;
$perp_togo -= 1;
}
}
foreach $key (1700,1800,1900,2100,2200,2300,2500,2600,2700) {
if ((($perp_year == $key) && ($perp_mon > 2))
  || ($perp_year > $key)) {
$perp_days -= 1;
}
}
$perp_dow = $perp_days - (int($perp_days/7)*7);
if ($perp_dow == 7) { $perp_dow = 0; }
if ($vars{monsunweek} eq "Yes") {
$perp_dow -= 1;
if ($perp_dow == -1) { $perp_dow = 6; }
}
$perp_eom = 31;
if (($perp_mon == 4) || ($perp_mon == 6)
  || ($perp_mon == 9) || ($perp_mon == 11)) {
$perp_eom = 30;
}
if (($perp_mon == 2)) {
$perp_eom = 28;
}
if ((int(($perp_year-1600)/4) eq (($perp_year-1600)/4))
  && ($perp_mon == 2)) {
$perp_eom = 29;
}
foreach $key (1700,1800,1900,2100,2200,2300,2500,2600,2700) {
if ($perp_year == $key) {
if ($perp_mon == 1) {
$perp_togo -= 1;
}
elsif ($perp_mon == 2) {
$perp_togo -= 1;
$perp_eom = 28;
}
else {
$perp_sofar -= 1;
}
}
}
}

如果需要修饰的话,自已去做吧 ! :-)

[关闭][返回]