Forum Moderators: coopster & phranque

Message Too Old, No Replies

Reading a file's last-modified time in Perl

         

mdharrold

12:37 am on Apr 27, 2002 (gmt 0)

10+ Year Member



Do you have a fix for this, Sugarkane?

List files based on modification date.

The only perl thing I can find is utime and all of the documentation I have seen on this tells how to modify existing times rather than retrieve existing times.

sugarkane

8:58 am on Apr 29, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Check out the 'stat' function (perldoc -f stat). Briefly, it returns an array full of useful info about a file:
[perl]
@array=stat($filehandle);
[/perl]

The modification time is stored in unix format in $array[9]

Brett_Tabke

10:19 am on Apr 29, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Or explicitly:

($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat($filepath);

mdharrold

1:20 am on Apr 30, 2002 (gmt 0)

10+ Year Member



This looks like a really bad way to handle a large amount of files.

DrDoc

4:59 pm on Apr 30, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, you can always list them using eval() and the *nix ls command .. and just filter the output ..