カレンダー
#! /usr/local/bin/perl $time = time; ($sec, $min, $hour, $date, $mon, $year, $wday) = localtime($time); $year += 1900; $mon++; $startwday = ($wday - $date % 7 + 1 + 7) % 7; # 今月1日の曜日 @days = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); if($mon == 2 and ($year % 4 == 0 and $year % 100 != 0 or $year % 400 == 0)) { $days[1]++; # うるう年 } $enddate = $days[$mon - 1]; # 月の日数 print qq(Content-type: text/html; charset=Shift_JIS\n\n); print <<END; <html> <head> <title>カレンダー $year年$mon月</title> </head> <body> <table border="5" bordercolor="#ffccff" cellspacing="0" cellpadding="5"> <tr> <th colspan="7">$year年$mon月</th> </tr> <tr> <td style="font-size:x-small;color:red">日</td> <td style="font-size:x-small">月</td> <td style="font-size:x-small">火</td> <td style="font-size:x-small">水</td> <td style="font-size:x-small">木</td> <td style="font-size:x-small">金</td> <td style="font-size:x-small;color:blue">土</td> </tr> END for($i = 0 ; $i < $startwday ; $i++) { # 1日までの空欄 if(($count % 7) == 0) { print qq(<tr>); } print qq(<td> </td>); $count++; } for($i = 1 ; $i <= $enddate ; $i++) { # 日付を書き込む if(($count % 7) == 0) { print qq(<tr>); } print qq(<td align="right"); if($i == $date) { print qq( bgcolor="#eeffee"); } if(($count % 7) == 0) { print qq( style="color:red"); } if(($count % 7) == 6) { print qq( style="color:blue"); } print qq(>$i); print qq(</td>); $count++; if(($count % 7) == 0) { print qq(</tr>\n); } } for( ; ($count % 7) != 0 ; ) { # 最後の日からの空欄 print qq(<td> </td>); $count++; if(($count % 7) == 0) { print qq(</tr>\n); } } print <<END; </table> </center> </body> </html> END exit;
〔 実行する 〕