Dave's Brain

Browse - programming tips - perl moddate

Date: 2008may1
Language: perl
Keywords: moddate

Q.  How can I get a file's modified date?

A.  Here's how I do it:

sub getModDate($)
{
        my($file) = @_;
        my(@a) = stat($file);
        if (scalar(@a) <= 0) { return undef; }
        return $a[9];
}

# Example use:

use POSIX qw(strftime);

sub main()
{
	$md = getModDate('/etc/passwd');
	$md_str = strftime("%a %b %e %H:%M:%S %Y", localtime($md));
	print "md=$md md_str=$md_str\n";
}

main();

Add a comment

Sign in to add a comment
Copyright © 2008, dave - Code on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License.