在perl中使用stat()函数获取文件的一些属性。
my $mtime = (stat $file)[9];
will get the modified time in epoch time format.
Use (s)printf or POSIX::strftime to format the date.
Eg:
my @t = localtime $mtime;
$date = sprintf "%02u/%02u/%02u %02u:%02u:%02u", $t[4] + 1, $t[3], $t[5] % 100, $t[2], $t[1], $t[0];
print $date, "\n";
# or
use POSIX qw(strftime);
$date = strftime "%Y%m%d%H%M%S", (localtime $mtime)[0..5];
print $date, "\n";
关于stat()函数的可以得到其他文件属性,详情请参阅perldoc -f stat
一个获取文件更新时间的子程序
#!/usr/bin/perl -w
sub fileTimeDiff {
my $file = $_[0];
my $mtime=(stat $file)[9] or die "(can't find file).$!";
my $diff=time()-$mtime;
}
$diff=&fileTimeDiff($ARGV[0]);
print "\$diff is $diff\n";
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。