in reply to Sort files
No, at least not as desired.
There are two elements in each record, 0 and 1, yet you address 1 and 2.
One of the two elements is a string, yet you use the numerical compare (<=>) operator. Use the string one instead (cmp).
[stat]->[9] is needlessly slow. Use (stat)[9] instead.
You didn't specify how the string should be sorted, but I'm guessing you want to sort by mtime first, and by name last.
If my guess is correct, you get:
or the fastermy @sorted_files_Test_flat_file_write_over_name_only = map { $_->[0] } sort { $a->[1] <=> $b->[1] or $a->[0] cmp $b->[0] } map { [ $_, (stat)[9] ] } @files_Test_flat_file_write_over_name_only;
my @sorted_files_Test_flat_file_write_over_name_only = map { substr($_, 11) } sort map { sprintf('%011d%s', (stat)[9], $_) } @files_Test_flat_file_write_over_name_only;
Update: Formatting changes. Added code.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sort files
by salva (Canon) on Apr 13, 2006 at 15:56 UTC |