通过从彼此中减去两个日期时间对象,我遇到了一些问题.我使用以下代码:
$today = DateTime->now( time_zone => 'Europe/Berlin' );
my $dt1 = DateTime-> new (
year => 2011,
month => 08,
day => 08,
hour => 1,
minute => 0,
second => 4,
time_zone =>'Europe/Berlin'
);
print "DT1 : $dt1\n";
print "today: $today\n";
my $sub = $today->subtract_datetime($dt1);
print "sub days: ".$sub->days."\n";
Run Code Online (Sandbox Code Playgroud)
DT1的打印声明今天打印:
DT1 : 2011-08-08T01:00:04
today: 2011-08-16T08:34:10
Run Code Online (Sandbox Code Playgroud)
但是如果我在减法后打印$sub->days它显示1而不是8天的值.
我的减法中有错误吗?
非常感谢您的帮助.
我有一个文本文件,我想抓住以模式开头并以特定模式结束的特定行.例:
Text
Text
Startpattern
print this line
Print this line
print this line
Endpattern
Text
Text
Text
Run Code Online (Sandbox Code Playgroud)
还应打印开始图案和结束图案.我的第一次尝试并没有真正成功:
my $LOGFILE = "/var/log/logfile";
my @array;
# open the file (or die trying)
open(LOGFILE) or die("Could not open log file.");
foreach $line () {
if($line =~ m/Sstartpattern/i){
print $line;
foreach $line2 () {
if(!$line =~ m/Endpattern/i){
print $line2;
}
}
}
}
close(LOGFILE);
Run Code Online (Sandbox Code Playgroud)
在此先感谢您的帮助.