Re: How can I sort files by timestamp without slurping?



Hi,


I'm thinking on incorporating a timestamp sorting mechanism without
slurping.

You wouldn't slurp anything. You would just assign the _names_ of the
files to an array. Why would that be so bad?


If you have that much files that you do not want to put all names in an
array you could do following: (pseudocode)

1. open your directory
2. my $mtime_var, $filename;
2. read one/next file.
3. get mtime of file
4. if($mtime_var == 0) { $mtime_var = mtime of file }
5. if($mtime_var > mtime of file) { $mtime_var = mtime_of file; $filename =
name of file }
6. goto 2.


note: do not store your file in an array if you do the sorting that way.
you 'll end with an array with all files in it; so you will not save any
memory!!

HTH Martin

.



Relevant Pages