If you want to make it robust in the case of fields being different
length, like having entries with the day as "5" instead of "05", you can
put a >>.Int after the .comb(/\d+/) and that'll give you proper numeric
sorting for all fields regardless of width.
On 09/06/18 06:51, Timo Paulssen wrote:
> That's unnecessarily long and complicated, here's how you can do it much
> easier:
>
> @x.sort: {
> my ($month, $day, $year, $hour, $minute, $second) = .comb(/\d+/);
> ($year // 0, $month // 0, $day // 0, $hour // 0, $minute // 0,
> $second // 0, $_);
> }
>
> Trying it on some input data:
>
> cimtrak.log.06-08-2018_16:07:39.zip
> cimtrak.log.06-08-2018_17:07:39.zip
> cimtrak.log.07-08-2018_06:07:39.zip
> cimtrak.log.07-08-2018_16:07:39.zip
> cimtrak.log.12-08-2016_06:07:39.zip
> cookies
> asbestos
> fire engine
> perl6
> butterflies
>
> results in:
>
> asbestos
> butterflies
> cookies
> fire engine
> perl6
> cimtrak.log.12-08-2016_06:07:39.zip
> cimtrak.log.06-08-2018_16:07:39.zip
> cimtrak.log.06-08-2018_17:07:39.zip
> cimtrak.log.07-08-2018_06:07:39.zip
> cimtrak.log.07-08-2018_16:07:39.zip
>
> This is the schwartzian transform that was mentioned in another mail.
> why it wasn't actually shown, i have no clue :)
>
> Hope that helps
> - Timo