in reply to Re^2: Sort the file names a list
in thread Sort the file names a list
It is not good because using substr() to extract the sorting keys is very weak. If for instance, the file names extensions are changed, it will extract incorrect keys and, what is worst, without reporting any warning or error to the user!
Even if slower, using a regular expression to extract the keys is probably the best solution.
In any case, there is a faster (not recommendable either) method...
that on my computer runs as...... use Sort::Key qw(keysort); ... cmpthese(-3, { ... sk => ' use strict; use warnings; my @sorted = keysort { substr($_, -(19+20), 19) } @::LogFileLi +st; ', });
Note also that on my hardware, naive is actually faster than grt.Rate memoized st grt naive sk memoized 8784/s -- -26% -51% -54% -58% st 11894/s 35% -- -33% -38% -43% grt 17794/s 103% 50% -- -7% -14% naive 19207/s 119% 61% 8% -- -7% sk 20714/s 136% 74% 16% 8% --
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Sort the file names a list
by ikegami (Patriarch) on Sep 01, 2009 at 13:58 UTC |