Please bottom post....
Babale Fongo wrote:
It was just an attempt to see how someone else may tackle this issue. I thought of sorting, but I wasn't sure it will do exactly what I expect. Here is what I've have so far:
my $dir = "/mydir";
opendir(DH, "$dir") || die "Failed to open $dir: $!\n";
my $counter = 0; while (defined(my $file = readdir (DH))){ next if $file =~ /^\.+$/;
You need to check the above. It says skip a file if it starts with one or more dots and ends (read: file is only dots). /^\./ is probably sufficient to skip dot files.
push @files, $file;
Why not get your stat information here? Store the mtime and the file to a hash. Then you can sort the hash by the mtime. Because (theoretically) two files could be created at the same time you should use the file name as the key. Then sort by the value.
perldoc -f sort
Explains how to do such things.
# store filename and mtime to hash $files{$file} = (stat $file)[9];
$counter++;
} closedir (DH);
if ($counter > 7){
for (@files){ $file_mtime{$_} = (stat($_))[9];
Need to compare mtime here... }
# sort filenames by mtime my @sorted = sort { $files{$a} <=> $files{$b} } keys %files;
}
<snip>
http://danconia.org
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>