下面的程序打印以下数据:
Wed,Jun,13,10:37:34,2012,759,41,0,30,10,0,0,1
Wed,Jun,13,10:38:34,2012,767,33,0,25,6,0,0,2
Wed,Jun,13,10:39:34,2012,758,42,0,32,10,0,0,0
Wed,Jun,13,10:40:35,2012,758,42,0,29,11,0,0,2
Wed,Jun,13,10:41:35,2012,761,39,0,34,5,0,0,0
Wed,Jun,13,10:42:35,2012,769,31,0,22,6,0,0,3
Wed,Jun,13,10:43:35,2012,754,46,0,29,17,0,0,0
我需要每隔 5 分钟输出一次最大值(例如 769)。理想情况下,这将是 10:00:00 - 10:05:00 等。时间是军用时间(24 小时)。这样做的最佳方法是什么?请注意,我是 Perl 的初学者。下面是我的代码:
#!/usr/bin/perl
# This program displays the max thread count at 5 minute intervals and writes the lines to a CSV file.
use strict;
use warnings;
use diagnostics;
# Initialize functions
my @data;
my $line;
my @L1;
#my $outFivemin = "log_5min.csv";
#open (FiveMin, ">> $outFivemin");
# Open the error_log
open(FH, "error_log");
@data = <FH>;
# Filter the results to MPMStats only
sub findLines {
my @return = ();
foreach $line (@data) {
if ( ($line =~ /notice/) && ($line =~ /rdy/) ) {
$line =~ s/ /,/g;
my @L1 = split(/|notice|\[|,mpmstats:,|\t|rdy,|bsy,|rd,|wr,|ka,|log,|dns,|cls,/, $line);
$line =~ s/|notice|\[|,mpmstats:,|\t|rdy,|bsy,|rd,|wr,|ka,|log,|dns,|cls,//g;
push @return, join("", @L1);
}
}
return @return;
}
# Initializers for my data
my($dayOfWeek1,$month1,$dayOfMonth1,$time,$year1,$rdy,$bsy,$rd,$wr,$ka,$log,$dns);
my($cls);
# Create a 2D array
my @L2 = &findLines;
foreach my $line (@L2){
($dayOfWeek1, $month1, $dayOfMonth1, $time, $year1, $rdy, $bsy, $rd, $wr, $ka, $log, $dns, $cls) = split(/,/, $line);
print "$dayOfWeek1,$month1,$dayOfMonth1,$time,$year1,$rdy,$bsy,$rd,$wr,$ka,$log,$dns,$cls";
}