in reply to Sorting dates with the Schwartzian Transform
A Schwartzian Transform when all you have to do is parse dates? That will make things *slower*. Creating all those arrays and references adds up.
This could speed up the sorting (because it creates few extra variables and it uses the specially optimised $a cmp $b callback):
my @sorted = map substr($_, 8), sort map join('', (/(..)-(..)-(....)/)[2,1,0], $_), @dates; # DD-MM-YYYY
Naïve:
my @sorted = sort { join('', ($a =~ /(..)-(..)-(....)/)[2,1,0]) cmp join('', ($b =~ /(..)-(..)-(....)/)[2,1,0]) } @dates; # DD-MM-YYYY
Schwartzian Transform:
my @sorted = map $_->[0], sort { $a->[1] cmp $b->[1] } map [ $_, join('', (/(..)-(..)-(....)/)[2,1,0]) ], @dates; # DD-MM-YYYY
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Sorting dates with the Schwartzian Transform
by Wobbel (Acolyte) on Aug 03, 2011 at 19:11 UTC | |
Re^2: Sorting dates with the Schwartzian Transform
by Wobbel (Acolyte) on Aug 15, 2011 at 13:19 UTC | |
by Anonymous Monk on Aug 15, 2011 at 14:19 UTC | |
by Wobbel (Acolyte) on Aug 16, 2011 at 19:17 UTC |
In Section
Seekers of Perl Wisdom