Forum Moderators: coopster

Message Too Old, No Replies

Date Stamps on Redhat/Linux

         

grummz

8:52 am on Apr 8, 2003 (gmt 0)



Argh...

I need to use Perl to sort a directory and sort the files in order of date. I know there is a date stamp because when I do an "ls" or view the files in my ftp viewer, there are dates like 4/3/03.

However, I can't figure out how to access it from Perl. I tried using:

(stat($gallerypath . $b)) [9] <=> (stat($gallerypath . $a)) [9]

As my sort function, but it only uses the timestamp which is NOT the date. How do I access the date to sort on?

HELP! :)

Josk

9:10 am on Apr 8, 2003 (gmt 0)

10+ Year Member



Why not just use ls and back tick it? Take a look at the man page for ls for all the options and use something like $listing = `ls`

ShawnR

10:15 am on Apr 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My view is that it is best to use a built-in perl function whenever one exists, rather than use a backtick'ed expression. That way you write code which is more portable.

I don't see anything wrong with your syntax of

(stat($gallerypath . $b))[9]

Perhaps approach it by divide and conquer. i.e. put debug statements in such as:

print (stat($gallerypath . $b)) [9], "\n";

(stat($gallerypath . $b))[9] returns the time in seconds since 1 Jan 1970, hence includes the full date, not just the time. Possibly the problem is somewhere else in your sort routine?

Note:
(stat($gallerypath . $b))[9] returns the time of last mod
(stat($gallerypath . $b))[10] returns the time of creation

Shawn

ShawnR

10:28 am on Apr 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



PS If you are trying to do something like sort on date, and sub-sort on some other parameter, such as alphabetically, gmtime() or localtime() can convert the results of (stat($gallerypath . $b))[9] into day, month, year, etc

Shawn