Re: How can I sort files by timestamp without slurping?



icarus wrote:
How can I sort files by timestamp without slurping?

the idea is to look into a directory, pick up the oldest first and so
on until the 'youngest' one.
file100..all the way to file1.

I found this solution somewhere,

my @sorted = map { $_->[0] }
sort { $b->[1] <=> $a->[1] }
map { [ $_, -M $_ ] }
@files;

By the looks of it, it does slurp the all the files from the source
directory into an array and does the sorting there.

I'm thinking on incorporating a timestamp sorting mechanism without
slurping.

You wouldn't slurp anything. You would just assign the _names_ of the files to an array. Why would that be so bad?

Since above solution looks like sorcery of some kind to me,

Then don't just look "somewhere", but study the Perl documentation on sorting.

perldoc -f sort

How can I modify it to fit below? or if you have any other ideas
please let me know. Thanks in advance.

MOVE_FILES:
while (defined (my $file = readdir (SOURCEDIR))){

#skip . and .. files
next MOVE_FILES if $file =~ m#^\.\.?$#;

#the sorting should it take place here I guess.


#move files
move ($file, $target_path) or die $!;

How would you be able to "sort" one item at a time?

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
.



Relevant Pages

  • Re: A Fast sorting algorithm for almost sorted data
    ... far my compressor has potential but is nowhere near ready. ... It does however make heavy use of sorting. ... which I am currently calling Run sort. ... entire selected run can be added to the sorted output array. ...
    (comp.compression)
  • Re: Ranking Without Sorting
    ... >> sorting the elements of the array. ... > inverting and applying such a permutation can be done in linear time. ... > You can avoid having to sort the input array by treating the output ...
    (comp.programming)
  • Re: Ranking Without Sorting
    ... > sorting the elements of the array. ... inverting and applying such a permutation can be done in linear time. ... You can avoid having to sort the input array by treating the output ...
    (comp.programming)
  • Re: Ranking Without Sorting
    ... >> contradicted in my first post where I gave an example of how to rank ... > It seems quite clear to me that your 'ranking' array contains the exact ... An unsorted array contains the same information as the same array after sorting. ... > the same operation as the insertion loop in insertion sort... ...
    (comp.programming)
  • Re: Efficiently Extracting Identical Values From A List/Array
    ... struct SortHelper ... Now sort that array according to NodeIndex: ... running through the data structure and sorting things out. ...
    (comp.lang.cpp)