Suppose I have a filehandle $fh
. I can check its existence with -e $fh
or its file size with -s $fh
or a slew of additional informati
I think you're looking for the stat
function (perldoc -f stat
)
In particular, the 9th field (10th, index #9) of the returned list is the last modify time of the file in seconds since the epoch.
So:
my $last_modified = (stat($fh))[9];
This is very old thread, but I tried using the solution and could not get the information out of File::stat. (Perl 5.10.1)
I had to do the following:
my $f_stats = stat($fh);
my $timestamp_mod = localtime($f_stats->mtime);
print "MOD_TIME = $timestamp_mod \n";
Just thought I share in case anyone else had the same trouble.
On my FreeBSD system, stat
just returns a bless.
$VAR1 = bless( [
102,
8,
33188,
1,
0,
0,
661,
276,
1372816636,
1372755222,
1372755233,
32768,
8
], 'File::stat' );
You need to extract mtime
like this:
my @ABC = (stat($my_file));
print "-----------$ABC['File::stat'][9] ------------------------\n";
or
print "-----------$ABC[0][9] ------------------------\n";