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



tester_V
Novice

Nov 18, 2017, 2:40 PM


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

Excellent!

I really appreciate your help!

As I said I cannot install any modules on the PC so "use List::UtilsBy qw(sort_by); " is out of the question.
The code works great if it is used with this input:

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 /;

but if the lines are inside the "Flow.txt" file then the code sorts the lines but produces 2 types of error:

Unsuccessful stat on filename containing newline at...
Use of uninitialized value in numeric comparison (<=>) at C:....

It also does not remove the newest file from the list.

Thanks for trying!

Here your code modified little bit my me:

#!/usr/local/bin/perl
use strict ;
use warnings ;

my $filename = "C:/Sixshot_logs/Flow.txt" ;
open (my $filename_fh, '<', $filename) or die $!;

my @file_list = <$filename_fh>;
# print " @file_list \n" ;
close $filename_fh;

my @file_modify_times = map { [ $_, (stat($_))[8] ] } @file_list;
my @files_sorted_by_mtime = sort { $a->[1] <=> $b->[1] } @file_modify_times;
#print "@files_sorted_by_mtime \n" ;
my @sorted_files = map { $_->[0] } @files_sorted_by_mtime;
print "@sorted_files \n" ;


Code
 


Thank you again for your help!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Forgot one thing.
The list of logs have extensions ".log"
So it is:
Rbck_flow_log.2017-10-01.1.log
Rbck_flow_log.2017-10-01.2.log
Rbck_flow_log.2017-10-01.13.log
Rbck_flow_log.2017-10-01.4.log
Rbck_flow_log.2017-10-01.10.log
Rbck_flow_log.2017-10-01.3.log
Rbck_flow_log.2017-10-01.12.log

Not :

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

Code


	

(This post was edited by tester_V on Nov 18, 2017, 3:03 PM)


Edit Log:
Post edited by tester_V (Novice) on Nov 18, 2017, 3:03 PM


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

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