- or download this
my @sorted = sort mysort @unsorted;
sub mysort
{
...
$bb = "$2 $1";
return $aa cmp $bb;
}
- or download this
@unsorted = ("Larry Wall", "Arthur C. Clarke");
@a = map { m/(.*?)\s*(\S+)$/; [$_, "$2 $1" ] } @unsorted;
#
# now @a is (["Larry Wall", "Wall Larry"],
# ["Arthur C. Clarke", "Clarke Arthur C."])
#
- or download this
my @sorted =
map{ $_->[0] }
sort {$a->[1] cmp $b->[1]}
map { m/(.*?)\s*(\S+)$/; [$_, "$2 $1" ] }
@unsorted;
- or download this
#!/usr/bin/perl
use Benchmark;
...
$bb = "$2 $1";
return $aa cmp $bb;
}
- or download this
Benchmark: timing 100000 iterations of schwartzian, sort routine...
schwartzian: 57 wallclock secs (53.66 usr + 0.30 sys = 53.96 CPU)
sort routine: 124 wallclock secs (122.48 usr + 0.41 sys = 122.89 CPU)