in reply to The Dates Sorting!

Working with dates can be tricky. There are many modules available, but for something this simple doing it the long way should be find. The stat function can be used to get the mtime of a file. The mtime is an epoch value (your file's age in seconds since January 1, 1970). This can be used to sort the list. If you are dealing with subdirectores, use the File::Find module.
[matt@test ~/testdir]$ stat -c %Y AMR.xml 1206990376
#!/usr/bin/perl use strict; use POSIX qw(strftime); my $dir = '/your/dir'; opendir DIR, $dir or die $!; my @files = grep { /\.xml$/ && ! /^\./ } readdir DIR; closedir DIR; my %ds; for my $file (@files) { my $mtime = (stat("/your/dir/$file"))[9]; $ds{$file} = $mtime; } for my $sorted_file (sort { $ds{$a} <=> $ds{$b} } keys %ds) { my $file_date = strftime("%Y-%m-%d", localtime($ds{$sorted_file})) +; my $file_time = strftime("%H:%M:%S", localtime($ds{$sorted_file})) +; print qq[<option value="$sorted_file">$file_date $file_time</optio +n>\n]; }

Replies are listed 'Best First'.
Re^2: The Dates Sorting!
by ack (Deacon) on Apr 04, 2008 at 17:35 UTC

    Good points.

    The only problem with the mtime stat on a file is that it may or may not have anything to do with the time encoded in the filename that the OP was interested in. So that may or may not be helpful for the OP.

    But if it turns out to, indeed, be applicable, then, to me, it sure would simplify the code and make the sorting even more compact.

    ack Albuquerque, NM