指定の日までの日数を表示
#! /usr/local/bin/perl
$targetM = 12; # 月の指定
$targetD = 25; # 日の指定
$time = time; # 日時取得
for($i = 0 ; $i <= 365 ; $i++) { # 今日から365日後まで調べる
my $check = $time + ($i * 24 * 60 * 60);
my ($sec, $min, $hour, $date, $mon, $year) = localtime $check;
++$mon;
if($mon == $targetM and $date == $targetD) { # 指定の日かチェック
$count = $i; # 指定の日までの日数
last;
}
}
# HTML出力
print qq(Content-type: text/html; charset=UTF-8\n\n);
print qq(<html>\n);
print qq(<head>\n);
print qq(<title>指定の日までの日数を表示</title>\n);
print qq(</head>\n);
print qq(<body>\n);
if($count == 0) {
print qq(<font size="+2">メリークリスマス!!</font><br>\n);
}
else {
print qq(クリスマスまで <font size="+2">あと$count日</font> です<br>\n);
}
print qq(</body>\n);
print qq(</html>\n);
exit;
〔 実行する 〕