如何检查Perl 6中的文件时间戳属性?

时间:2015-05-15 16:34:54

标签: perl timestamp perl6

在Perl 5中,您可以使用stat来获取文件的访问,修改和更改时间戳。

例如:

my $filename = "sample.txt";
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
       $atime,$mtime,$ctime,$blksize,$blocks)
           = stat($filename)

print "File '$filename' was last accessed $atime seconds since the epoch.\n";

结果是:

File 'sample.txt' was last accessed 1431707004 seconds since the epoch.

如何在Perl 6中检查文件时间戳?

1 个答案:

答案 0 :(得分:4)

Perl 6中的file test operators from Perl 5是来自IO::FileTestable role的方法(例如.modified.accessed.changed)。

例如:

my $filename = "sample.txt";
my $seconds_since_epoch = $filename.IO.accessed;
my $readable_timestamp  = DateTime.new($filename.IO.accessed);

say "File '$filename' was last accessed at '$readable_timestamp', which is {$seconds_since_epoch.Num} seconds since the epoch";

在我的情况下,给了:

File 'sample.txt' was last accessed at '2015-05-15T16:22:49Z', which is 1431707004 seconds since the epoch