in reply to Sort directories by date
I usually would not care that much about that with a short list of subdirectories, but it sometimes matter that there are more efficient algorithms to pick up the latest (or largest, or smallest, whatever) element in a list.
For example, something like this at the command line (quick test):
This may look slightly more complex, but it is more efficient for a long list of directories. Which is why I would care only if the list is long.$ perl -e ' > my @list = qw/12112014 > 01052015 > 02202015 > 03102015 > 01012011 > 10102014 > 04092015 > 09092015 > 09092013/; > chomp @list; > my $max_y = "0000"; > my $max_d = "0000"; > for my $dir (@list) { > my ($d, $y) = $dir =~ /(\d{4})(\d{4})/; > if ($y > $max_y) { > $max_y = $y; > } elsif ($y == $max_y) { > $max_d = $d if $d > $max_d; > } > } > print "$max_d$max_y\n"; > ' 09092015
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sort directories by date
by AnomalousMonk (Archbishop) on Sep 29, 2015 at 16:18 UTC | |
by Laurent_R (Canon) on Sep 29, 2015 at 18:52 UTC |