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
In reply to Re: Sorting dates with the Schwartzian Transform
by ikegami
in thread Sorting dates with the Schwartzian Transform
by Wobbel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |