#!/usr/bin/perl
@month = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
@week = ("Sunday", "Monday","Tuesday", "Wednesday","Thursday", "Friday",
"Saturday");
print "date:\n";
$date=<STDIN>;
print "mon:\n";
$mon=<STDIN>;
print "year:\n";
$year=<STDIN>;
if (($year % 400 == 0) || ($year % 4 == 0) && ($year % 100 != 0))
{
$month[1] = 29 ;
for($i = 0 ; $i < $mon - 1 ; $i++)
{
$s = $s + $month[$i] ;
$s = $s + ($date + $year + ($year/4) - 2) ;
$s = $s % 7 ;
}
}
print $week[$s+1] ;
我一直在試圖學習perl幾天,我寫了代碼來查找給定日期的一天。實際上我從C代碼轉換了它。但它並不正確。輸出總是星期一。我在哪裏犯錯?從給定的日期找到一天
你應該縮進代碼COS這是非常難讀,但我看不到如果'$ year'不是閏年,它會在哪裏更新'$ s'? –