Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Perl将上次运行时写入文件_Perl_Date_Timestamp - Fatal编程技术网

Perl将上次运行时写入文件

Perl将上次运行时写入文件,perl,date,timestamp,Perl,Date,Timestamp,(perl新增) 我正在尝试更新一个现有的perl脚本,以便在上次运行它时将其存储在一个文件中,以便在下次运行时“自”该日期起执行某些操作 是否有一种安全的方法将其存储在一个文件中,然后我可以再次将其读入时间戳 我已经学会了如何写文件 # Open for writing open(MYFILE,">$filepath/$filename") || "> ERROR: Couldn't open file for writing\n"; print MYFILE $result; c

(perl新增)

我正在尝试更新一个现有的perl脚本,以便在上次运行它时将其存储在一个文件中,以便在下次运行时“自”该日期起执行某些操作

是否有一种安全的方法将其存储在一个文件中,然后我可以再次将其读入时间戳

我已经学会了如何写文件

# Open for writing
open(MYFILE,">$filepath/$filename") || "> ERROR: Couldn't open file for writing\n";
print MYFILE $result;
close MYFILE;
以及如何以字符串形式获取时间

my ($sec, $min, $hour, $day, $mon, $year) = localtime();
$LAST_RUN_DATETIME=strftime( "%Y/%m/%d %T", $sec, $min, $hour, $day, $mon, $year);

谢谢你的时间

我可能会写这样的东西:

open(my $handle, ">", "$filepath/$filename") or die "Couldn't open $file";
print $handle scalar(localtime());
close($handle);
阅读它只是:

open(my $handle, "$filepath/$filename") or die "Couldn't open $file";
my $timestamp = <$handle>;
open(我的$handle,“$filepath/$filename”)或die“无法打开$file”;
我的$timestamp=;

时间戳的形式如下:
(一周中的一天)mmm(一个月中的一天)hh:mm:ss yyyy
我可能会这样写:

open(my $handle, ">", "$filepath/$filename") or die "Couldn't open $file";
print $handle scalar(localtime());
close($handle);
阅读它只是:

open(my $handle, "$filepath/$filename") or die "Couldn't open $file";
my $timestamp = <$handle>;
open(我的$handle,“$filepath/$filename”)或die“无法打开$file”;
我的$timestamp=;

时间戳的形式如下:
(一周中的一天)mmm(一个月中的一天)hh:mm:ss yyyy

您也可以打开和关闭文件,然后在文件上使用时间戳。(stat(filename))[9]将返回该文件。您也可以只打开和关闭该文件,然后在该文件上使用时间戳。(stat(filename))[9]将取回它。