in reply to Re: Sort directories by date
in thread Sort directories by date
It just occurred to me that a GRTish, guaranteed-single-pass solution is possible:
Use minstr for least-recent date. See the core module List::Util. No efficiency/performance testing done nor claims made. (Update: Actually, I'd be surprised if there's any advantage unless you're dealing with really large lists; default sort (with no subroutine block) is pretty fast!)c:\@Work\Perl\monks>perl -wMstrict -le "use List::Util qw(maxstr); ;; my @dates = qw( 12112014 12012014 01052015 12202014 12022014 02202015 03102015 01012011 09092015 04092015 ); ;; my $most_recent = unpack 'x4a*', maxstr map pack('a4a*', unpack('x4a4', $_), $_), @dates ; ;; print $most_recent; " 09092015
Update: See also pack, unpack, perlpacktut.
Give a man a fish: <%-{-{-{-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Sort directories by date
by Laurent_R (Canon) on Sep 29, 2015 at 18:52 UTC |