Laurent_R
Veteran
/ Moderator
Nov 18, 2017, 4:19 AM
Views: 24139

Re: [tester_V] delete the newest file from the list



OK, now I've found the time. This is a possible implementation of the Schwartzian transform for your data:
use strict; use warnings; use feature "say"; my @files = qw / Rbck_flow_log.20171001.1 Rbck_flow_log.20171001.2 Rbck_flow_log.20171001.13 Rbck_flow_log.20171001.4 Rbck_flow_log.20171001.10 Rbck_flow_log.20171001.3 Rbck_flow_log.20171001.12 /; my @sorted = map { join ".", @$_ } # putting things back together sort { $a>[1] cmp $b>[1] or $a>[2] <=> $b>[2]} # sorting on second and third fields map { [split /\./, $_]} @files; # splitting input strings intio array refs say for @sorted; You should read the transform part (map ... sort ... map) from bottom to top: first split the strings into array refs, then sort, then put things back together. And this prints out the following:
Rbck_flow_log.20171001.1 Rbck_flow_log.20171001.2 Rbck_flow_log.20171001.3 Rbck_flow_log.20171001.4 Rbck_flow_log.20171001.10 Rbck_flow_log.20171001.12 Rbck_flow_log.20171001.13
(This post was edited by Laurent_R on Nov 18, 2017, 4:22 AM)
