in reply to Find a file
I would recomment choosing a filename format that sorts alphabetically the same as cronologically, eg 2004.05.11.txt. Then all you need to do is read in the current directory, do a reverse sort on the filenames, and pick the first, eg
If you can't make your filenames sort like that, then you'll need to take the extra step of splitting apart the filename, egopendir D, '.'; @files = reverse sort grep $_ ne '.' && $_ ne '..', readdir D; if (@files) { email($files[0]); }
(The above is known as a Schwartzian transform)@files = map { $_->[0] } sort { $b->[1] <=> $a[1] } map { /^(..)(..)(..)/; [ $_, "$3$2$1" ] } grep $_ ne '.' && $_ ne '..', readdir D;
|
|---|