0
我使用Apache::Log::Parser解析Apache日誌文件。使用Time :: Piece with Apache :: Log :: Parser
我使用以下代碼從日誌文件中提取日期。
my $parser = Apache::Log::Parser->new(fast=>1);
my $log = $parser->parse($data);
$t = $log->{date};
現在,我試圖用Time::Piece解析日期,但我無法做到這一點。
print "$t->day_of_month";
但是,它不工作。如何使用Time :: Piece來解析日期?
刪除了雙引號,並且引發錯誤 '無法調用方法「day_of_month」沒有包或對象引用' – Pradeep
@Pradeep閱讀我答案的最後部分。您需要先創建一個對象。只要放入Time :: Piece就不會將某些值奇蹟般地轉換爲日期對象。 – simbabque
嘗試創建一個新的'Time :: Piece Object','Time :: Piece-> strptime($ log - > {date},「%Y」);' 但是一直拋出錯誤 ' :/xampp/perl/lib/Time/Piece.pm line 469' – Pradeep