打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
perl 获取文件时间的方法
userphoto

2015.10.12

关注
在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";
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
perl获得当期的日期和时间
dateutil 时间模块
Perl练习题,持续更新中...
文件添加,减少几行文字perl脚本
Git如何获得两个版本间所有变更的文件列表
Python 股票历史数据的获取
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服