in reply to Sort the file names a list
Sounds like you need a custom sort routine. There are several ways you could do it. Most simply (and least efficiently):
my @sorted = sort { (split /\./, $a)[1] cmp (split /\./, $b)[1] } @LogAnalyser::LogFileList;
A better way (that someone named something fancy which I cannot remember):
my @sorted = sort datestamp @LogAnalyser::LogFileList; { # anonymous block. If you're using Perl 5.10, you could # use a state variable instead. my %cache; sub datestamp { my $left = ( $cache{$a} ||= (split /\./, $a)[1] ); my $right = ( $cache{$b} ||= (split /\./, $b)[1] ); return $left cmp $right; } }
This last one does a little memory tradeoff to avoid doing the split and offset twice for every comparison in the sort.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sort the file names a list
by ikegami (Patriarch) on Aug 31, 2009 at 16:31 UTC | |
by bv (Friar) on Aug 31, 2009 at 16:42 UTC | |
by ikegami (Patriarch) on Aug 31, 2009 at 16:50 UTC | |
by bv (Friar) on Aug 31, 2009 at 17:11 UTC | |
by salva (Canon) on Sep 01, 2009 at 08:41 UTC | |
by ikegami (Patriarch) on Sep 01, 2009 at 13:58 UTC |