Re: reading a directory, first files the newest ones



Gunnar Hjalmarsson <noreply@xxxxxxxxx> wrote:
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";
}

....

The solution would be reading the newest ones first.

And that's what the -t option achieves...

No, the -t option tells ls to *present* the newest ones first, not to
read them first. To present them in that order, it first needs to read all
of the directory entries in whatever order the file system deigns to
deliver them, stat them all, and sort the results based on time. There is
no reason to think that ls is going to be meaningfully faster about this
than perl will.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
.



Relevant Pages

  • parse hash by array element seems to run slow
    ... I've been through the faq's and every web site that focuses on perl ... I iterate the array and search the hash keys to find a match and then ... foreach $verifyArr ...
    (comp.lang.perl.misc)
  • Perl crash related to Tie::File and hashes
    ... crash in perl when I try to use the data later on. ... sub TIEARRAY { ... foreach my $p { ... The assignment in the last loop causes perl to crash. ...
    (comp.lang.perl.moderated)
  • Re: Docs comprehensibility
    ... who started his programming 'career' a few years ago by modifying Matt ... to fix the Perl documentation. ... >> feel confident enough. ... Gunnar Hjalmarsson ...
    (comp.lang.perl.misc)
  • [DGBI] oops, obviously Ive missed something (was: regexp or array?)
    ... foreach { ... Better use an array of precompiled regexpes: ... perl -wle ' ... use Benchmark qw|cmpthese timethese|; ...
    (comp.lang.perl.misc)
  • Re: Search and replace problem
    ... the foreach part doesn't work. ... You are not using the natural representation of things. ... string, it's a precompiled regex. ... Why not just write Perl? ...
    (comp.lang.perl.misc)