Re: reading a directory, first files the newest ones
- From: Gunnar Hjalmarsson <noreply@xxxxxxxxx>
- Date: Sun, 28 Oct 2007 03:36:43 +0100
jordilin wrote:
On Oct 28, 2:02 am, Gunnar Hjalmarsson <nore...@xxxxxxxxx> wrote:Maybe you should let the system do the desired sorting. On *nix that
might be:
chomp( my @files = qx(ls -t $dir) );
foreach my $file (@files) {
last if -M "$dir/$file" > 2/24;
print "$file\n";
}
With this code, and taking into account that the directory is huge,
How big is "huge"?
memory usage would be a problem as we are going to use a huge array
@files, and the Unix server is a very important one. Don't know if
that could be achieved by means of a while. The real problem is having
to process many files before arriving to the interesting ones.
With the above suggestion you wouldn't _process_ any files but the interesting ones; you'd just store their names in an array.
The solution would be reading the newest ones first.
And that's what the -t option achieves...
I think there is no solution.
??
We have, either to slurp all the files into an array (which
is going to take time and memory), or process the whole directory
through a while (one file at a time) till we get the proper files,
which in this case is going to take a lot of time as well.
Have you measured the time for various options? You may want to study the Benchmark module.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
.
- Follow-Ups:
- Re: reading a directory, first files the newest ones
- From: xhoster
- Re: reading a directory, first files the newest ones
- References:
- reading a directory, first files the newest ones
- From: jordilin
- Re: reading a directory, first files the newest ones
- From: Gunnar Hjalmarsson
- Re: reading a directory, first files the newest ones
- From: jordilin
- reading a directory, first files the newest ones
- Prev by Date: Re: reading a directory, first files the newest ones
- Next by Date: Re: reading a directory, first files the newest ones
- Previous by thread: Re: reading a directory, first files the newest ones
- Next by thread: Re: reading a directory, first files the newest ones
- Index(es):