- or download this
@files = sort { my ($ad) = ( $a =~ /fwlog\.(\d+)\w+/ );
my ($bd) = ( $b =~ /fwlog\.(\d+)\w+/ );
$ad <=> $bd } @files;
- or download this
foo1.tla
foo10.tla
...
foo101.tla
foo102.tla
etc.
- or download this
sub naive {
sort {
...
$ma <=> $mb
} @_;
}
- or download this
sub orcish {
my %c;
...
$c{$a} <=> $c{$b};
} @_;
}
- or download this
sub schwartzian {
map { $_->[0] }
sort { $a->[1] <=> $b->[1] }
map { [ $_, /foo(\d+)\.tla/ ] } @_;
}
- or download this
sub guttros {
map { substr( $_, 3 ) }
sort
map { sprintf( "%03d", /foo(\d+)\.tla/ ) . $_ } @_;
}
- or download this
Benchmark: timing 5000 iterations of guttros, naive, orcish,
schwartzian...
...
( 0.04 usr + 0.00 sys = 0.04 CPU) @ 125000.00/s (n=5000)
schwartzian: 26 wallclock secs
(25.70 usr + 0.03 sys = 25.73 CPU) @ 194.33/s (n=5000)