Christopher Bottoms
Christopher Bottoms

Reputation: 11158

How do I check file timestamp attributes in Perl 6?

In Perl 5, you can use stat to get the accessed, modified, and changed timestamps of files.

For example:

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";

Which results in:

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

How do you check file time stamps in Perl 6?

Upvotes: 2

Views: 266

Answers (1)

Christopher Bottoms
Christopher Bottoms

Reputation: 11158

The file test operators from Perl 5, in Perl 6 are methods (e.g. .modified, .accessed and .changed) from the IO::FileTestable role.

For example:

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";

in my case, gave:

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

Upvotes: 4

Related Questions