Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Perl脚本追加日期_Perl_Perlscript - Fatal编程技术网

Perl脚本追加日期

Perl脚本追加日期,perl,perlscript,Perl,Perlscript,我每天都在我的服务器上运行这个perl脚本,并得到下面的脚本输出。我试图修改脚本,将当前小时作为输出的一部分。我该怎么做呢 这是我当前的脚本: #!/usr/bin/perl #Prism Performance log Parser use strict; my $cbal_total; my $cbal_count =0; my $stck_total = 0; my $stck_count =0; my $chg_total = 0; my $chg_count =0; my $rma

我每天都在我的服务器上运行这个perl脚本,并得到下面的脚本输出。我试图修改脚本,将当前小时作为输出的一部分。我该怎么做呢

这是我当前的脚本:

#!/usr/bin/perl
#Prism Performance log Parser

use strict;

my $cbal_total;
my $cbal_count =0;
my $stck_total = 0;
my $stck_count =0;
my $chg_total = 0;
my $chg_count =0;
my $rmac_total = 0;
my $rmac_count =0;
my $rmd_total = 0;
my $rmd_count =0;
my $cbalT;

my $stckT;
my $rmacT;
my $rmdT;
my $chgT;
my $total;
my $count;
my $cbal;
my $stck;
my $hour;


my $chg;
my $rmac;
my $rmd;

my $lesThresh=0;
my $gtThresh=0;
my $stck_lesThresh=0;
my $stck_gtThresh=0;
my $rmd_lesThresh=0;
my $rmd_gtThresh=0;
my $chg_lesThresh=0;
my $chg_gtThresh=0;
my $rmac_lesThresh=0;
my $rmac_gtThresh=0;

my %CheckBal;
my %SubTypeCheck;
my %charging;
my %remoteAct;
my %remoteDct;

my $chgkey;
my $cbalkey;
my $stckkey;
my $rmackey;
my $rmdkey;

my @value;
my $ct;
my $component;
my $component2;

while (my $line =<>) {
    chomp;
    s/\r//g;
    my @f = split(/\|/, $line);
    my $i;
    $hour = substr($f[0],11,2);

    for ($i==0;$i<=100; $i++) {
        if (($f[$i]=~m/CBAL/) && ($f[$i]!~m/CBAL,100/)) {
            $component="CBAL";
            $cbal=$f[$i];
            $cbalkey="$hour,$component";
            if (!exists($CheckBal{$cbalkey})) {
                $cbal_count=0;
                $cbal_total=0;
                $lesThresh=0;
                $gtThresh=0;
            }
            $cbalT = substr($cbal,index($cbal,",T=")+3,index($cbal,"\n"));
            if ($cbalT <= 300) {
                $lesThresh++;
            }else{
                $gtThresh++
            }
            $cbal_total +=$cbalT;
            $cbal_count ++;
            #$CheckBal{$cbalkey} =($cbal_total).",".($cbal_count).",".($lesThresh).",".$gtThresh.",".($cbal_total/$cbal_count);
            $CheckBal{$cbalkey} =($cbal_count).",".($cbal_total).",".($cbal_total/$cbal_count).",".($lesThresh).",".$gtThresh;

        }elsif($f[$i]=~m/STCK/){
            $component="STCK";
            $stck=$f[$i];
            $stckkey="$hour,$component";
            if (!exists($SubTypeCheck{$stckkey})) {
                $stck_count=0;
                $stck_total=0;
                $stck_lesThresh=0;
                $stck_gtThresh=0
            }
            $stckT = substr($stck,index($stck,",T=")+3,index($stck,"\n"));
            if ($stckT <= 300) {
                $stck_lesThresh++;
            }else{
                $stck_gtThresh++
            }
            $stck_total +=$stckT;
            $stck_count ++;
#           $SubTypeCheck{$stckkey} =($stck_total).",".($stck_count).",".($stck_lesThresh).",".$stck_gtThresh.",".($stck_total/$stck_count);
            $SubTypeCheck{$stckkey} =($stck_count).",".($stck_total).",".($stck_total/$stck_count).",".($stck_lesThresh).",".$stck_gtThresh;

        }elsif($f[$i]=~m/CHG/){
            $component="CHG";
            $chg=$f[$i];
            $chgkey="$hour,$component";
            if (!exists($charging{$chgkey})) {
                $chg_count=0;
                $chg_total=0;
                $chg_lesThresh=0;
                $chg_gtThresh=0
            }
            $chgT = substr($chg,index($chg,",T=")+3,index($chg,"\n"));
            if ($chgT <= 300) {
                $chg_lesThresh++;
            }else{
                $chg_gtThresh++
            }
            $chg_total +=$chgT;
            $chg_count ++;
#           $charging{$chgkey} =($chg_total).",".($chg_count).",".($chg_lesThresh).",".$chg_gtThresh.",".($chg_total/$chg_count);
            $charging{$chgkey} =($chg_count).",".($chg_total).",".($chg_total/$chg_count).",".($chg_lesThresh).",".$chg_gtThresh;
        }elsif(($f[$i]=~m/RMAC/) && ($f[$i]!~m/RMAC,96/)){
            $component="RMAC";
            $rmac=$f[$i];
            $rmackey="$hour,$component";
            if (!exists($remoteAct{$rmackey})) {
                $rmac_count=0;
                $rmac_total=0;
                $rmac_lesThresh=0;
                $rmac_gtThresh=0
            }
            $rmacT = substr($rmac,index($rmac,",T=")+3,index($rmac,"\n"));
            if ($rmacT <= 300) {
                $rmac_lesThresh++;
            }else{
                $rmac_gtThresh++
            }
            $rmac_total +=$rmacT;
            $rmac_count ++;
#           $remoteAct{$rmackey} =($rmac_total).",".($rmac_count).",".($rmac_lesThresh).",".$rmac_gtThresh.",".($rmac_total/$rmac_count);
            $remoteAct{$rmackey} =($rmac_count).",".($rmac_total).",".($rmac_total/$rmac_count).",".($rmac_lesThresh).",".$rmac_gtThresh;

        }elsif(($f[$i]=~m/RMD/) && ($f[$i]!~m/RMD,96/)){
            $component="RMD";
            $rmd=$f[$i];
            $rmdkey="$hour,$component";
            if (!exists($remoteDct{$rmdkey})) {
                $rmd_count=0;
                $rmd_total=0;
                $rmd_lesThresh=0;
                $rmd_gtThresh=0
            }
            $rmdT = substr($rmd,index($rmd,",T=")+3,index($rmd,"\n"));
            if ($rmdT <= 300) {
                $rmd_lesThresh++;
            }else{
                $rmd_gtThresh++
            }
            $rmd_total +=$rmdT;
            $rmd_count ++;
#           $remoteDct{$rmdkey} =($rmd_total).",".($rmd_count).",".($rmd_lesThresh).",".$rmd_gtThresh.",".($rmd_total/$rmd_count);
            $remoteDct{$rmdkey} =($rmd_count).",".($rmd_total).",".($rmd_total/$rmd_count).",".($rmd_lesThresh).",".$rmd_gtThresh;

        }


    }

}


print "Balance Check\n";
print "Hour,Task,Total Transactions,Total Processing Time/ms,Average TPS/ms,<300 ms,>300 ms\n";
unless(%CheckBal){
    print "No record found for STCK\n";
}
foreach (sort keys %CheckBal){
    print $_.",".$CheckBal{$_}."\n";
}
#/usr/bin/perl
#Prism性能日志解析器
严格使用;
我的$cbal_总计;
我的$cbal_计数=0;
我的$stck_总计=0;
我的$stck\u计数=0;
我的$chg_总计=0;
我的$chg_计数=0;
我的$rmac_总计=0;
我的$rmac_计数=0;
我的$rmd_总计=0;
我的$rmd_计数=0;
我的$cbalT;
我的$stckT;
我的$rmacT;
我的$rmdT;
我的$chgT;
我的$total;
我的$count;
我的$cbal;
我的$stck;
我的$hour;
我的$chg;
我的$rmac;
我的$rmd;
我的$Lestresh=0;
我的$gtThresh=0;
我的$stck_lestresh=0;
我的$stck_gtThresh=0;
我的$rmd_Lestresh=0;
我的$RMDgtthresh=0;
我的$chg_Lestresh=0;
我的$CHGgthresh=0;
我的$rmac_Lestresh=0;
我的$RMACgtthresh=0;
我的%CheckBal;
我的支票;
我的%收费;
我的行为;
我的%remoteDct;
我的$chgkey;
我的$cbalkey;
我的$stckkey;
我的$rmackey;
我的$rmdkey;
我的价值;
我的$ct;
我的$component;
我的$component2;
while(我的$line=){
咀嚼;
s/\r//g;
my@f=拆分(/\\\124;/,$line);
我的$i;
$hour=substr($f[0],11,2);

对于($i==0;$i要获取当前小时,请使用


如何在脚本中插入该功能对您来说是一个练习。

我想您忘记了实际包含输出。如果您想在perl脚本中包含时间信息,您应该查看。hi添加了所有信息如果您只想让某人为您修复脚本,您是否考虑过雇佣perl程序mer?我明白你为什么没有做任何工作了。这个脚本非常糟糕。执行不好,变量名不好,没有注释。我至少格式化了缩进以帮助突出显示逻辑。看来
%CheckBal
包含了要打印的整个格式化行,所以这个变量必须自己修改。它看起来像date是数据的一部分,但如果没有数据,我甚至不能说如何开始。添加
使用警告;
,因为我在程序本身中看到两个错误。
使用警告;
将指出它们。
Balance Check
Hour,Task,Total Transactions,Total Processing Time/ms,Average TPS/ms,<300 ms,>300 ms
06,CBAL,17987,13131831,730.073441930283,4295,13692
07,CBAL,17911,13579801,758.182178549495,3970,13941
08,CBAL,228,98643,432.644736842105,100,128
Balance Check
date,Hour,Task,Total Transactions,Total Processing Time/ms,Average TPS/ms,<300 ms,>300 ms
20140528,06,CBAL,17987,13131831,730.073441930283,4295,13692
20140528,07,CBAL,17911,13579801,758.182178549495,3970,13941
20140528,08,CBAL,228,98643,432.644736842105,100,128
 use strict;
 use warnings;

 use Time::Piece;

 print localtime->strftime("%H"), "\n";