Programming Tips - perl: get a file's modified time (seconds since start of epoch)

Date: 2008may1 Updated: 2020oct27 Language: perl Keywords: moddate, mtime, modtime, modify, modified Q. perl: get a file's modified time (seconds since start of epoch) A. Here's how I do it:
# Does NOT use CPAN libraries, etc sub getModifyTime($) { my($file) = @_; my(@a) = stat($file); if (scalar(@a) <= 0) { return undef; } return $a[9]; } # Example use: use POSIX qw(strftime); sub main() { my $mt = getModifyTime('/etc/passwd'); my $str = strftime("%a %b %e %H:%M:%S %Y", localtime($mt)); print "mt=$mt str=$str\n"; } main();