
tester_V
Novice
Nov 19, 2017, 1:41 AM
Post #3 of 8
(6443 views)
|
Re: [Laurent_R] System call fro Perl script
[In reply to]
|
Can't Post
|
|
Hi Lauren, I decided to try PM modules you guys suggested on a PC that has internet access and have to tell you those modules making life much easier. Anyway, I installed <Sort::Naturally> module and a <Tie::File >and it is working amazingly well. There is a little problem with the <Tie::File > part of the code, It fails to execute (remove last line from a file) but if I ran it separately it is working fine. I thought maybe it is a good idea to make a separate script and just call it from the main script. I’m using the same log files for processing. Here is code that does not work.
#!/usr/local/bin/perl use strict ; use warnings ; use File::Copy; use Sort::Naturally ; my $low = "C:/Sixshot_logs/Flow.txt" ; my $flow_sorted = "C:/Sixshot_logs/Flow-Sorted.txt" ; open (my $flow_sorted_fh,'>',$flow_sorted) or die "Cannot open $flow_sorted $!" ; open (my $low_fh, '<', $low) or die $!; my @file_list = <$low_fh>; close $low_fh; my @list = nsort (@file_list) ; print $flow_sorted_fh "@list \n" ; close $low_fh ; close $flow_sorted_fh ; use Tie::File ; use Tie::Array; # Have to use this use Tie::Arrey ## my $cleand_Flow_f = "C:/Sixshot_logs/Flow-Sorted.txt" ; tie my @lines_c, 'Tie::File', $cleand_Flow_f or die "can't update $cleand_Flow_f: $!"; delete $lines_c[-1]; exit ;
|