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 information about the file. How can I get its last modified time stamp?
Suppose I have a filehandle $fh . I can check its existence with -e
Share
Calling the built-in function
stat($fh)returns an array with the following information about the file handle passed in (from the perlfunc man page forstat):Element number 9 in this array will give you the last modified time since the epoch (00:00 January 1, 1970 GMT). From that you can determine the local time:
Alternatively, you can use the built-in module
File::stat(included as of Perl 5.004) for a more object-oriented interface.And to avoid the magic number 9 needed in the previous example, additionally use
Time::localtime, another built-in module (also included as of Perl 5.004). Together these lead to some (arguably) more legible code: