my $path="/mnt/splash/logs/";
my $serv= sprintf("splash-%s-%02d%02d%02d-%s",$server,$year,$mon,$date,$hourStart);
my $eserv= sprintf("splash-%s-%02d%02d%02d-%s",$server,$eyear,$emon,$edate,$hourEnd);
print $serv;
print $eserv;
#OPEN THE SPLASH LOGS DIRECTORY AND READ THE FILES PRESENT THEN STORE IT IN ARRAY.
my $remote_dir=sprintf("ssh %s 'ls %s'",$server,$path);
chomp $remote_dir;
my @list=`$remote_dir`;
#FINDING THE ONLY SPLASH LOGS FILES FROM THE DIRECTORY AND STORED IN AN ARRAY USING PUSH METHOD.
my @srt_list= sort @list;
my @arlist=();
my @arrlog=();
my $i=0;
my $filt;
for(@srt_list) {
if ($_ ge $serv && $_ le $eserv) {
#my $filter= sprintf("$_n");
chomp $_;
push (@arrlog, $_);
}
}
上面是我用来从数组中检索日志的perl代码。我在ge
和le
操作员中使用了if
条件不检索log 20160629-1000。我不知道这是怎么发生的,我使用了le操作员,这意味着它应该选择小于或平等的日志的日志?
请澄清一下。我真的不想添加其他检查来检索结束时间日志。
而无需看到您的输入数据,我将不得不猜测。
但是,从您所拥有的,我猜您正在比较:
20160629-1000
带有 20160629-1000.log
末端的后缀使其在字母内"更大"。
print "yes" if "20160629-1000" le "20160629-1000.log";
print "no" if "20160629-1000.log" le "20160629-1000";
那是因为le
是一个弦乐比较,而不是数字。
简单的修复是剥离后缀:
for (@srt_list) {
my ($compare) = m/(splash.*[d-]+).log/;
print "Comparing $compare with $serv and $eservn";
if ($compare ge $serv && $compare le $eserv) {
chomp $_;
push (@arrlog, $_);
}
}