CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [tester_V] delete the newest file from the list: Edit Log



Laurent_R
Veteran / Moderator

Nov 18, 2017, 4:19 AM


Views: 20267
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:


Code
use strict; 
use warnings;
use feature "say";

my @files = qw /
Rbck_flow_log.2017-10-01.1
Rbck_flow_log.2017-10-01.2
Rbck_flow_log.2017-10-01.13
Rbck_flow_log.2017-10-01.4
Rbck_flow_log.2017-10-01.10
Rbck_flow_log.2017-10-01.3
Rbck_flow_log.2017-10-01.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:

Code
Rbck_flow_log.2017-10-01.1 
Rbck_flow_log.2017-10-01.2
Rbck_flow_log.2017-10-01.3
Rbck_flow_log.2017-10-01.4
Rbck_flow_log.2017-10-01.10
Rbck_flow_log.2017-10-01.12
Rbck_flow_log.2017-10-01.13



(This post was edited by Laurent_R on Nov 18, 2017, 4:22 AM)


Edit Log:
Post edited by Laurent_R (Veteran) on Nov 18, 2017, 4:22 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives