title: Perl script appending date
body: <p>Am running this perl script ever day on my server and am getting the below output for the script. I am trying to modify the script to also include the current hour as part of the output.  How can I go about doing this?</p>
  
  <p>This is my current script:  </p>
  
  <pre><code>#!/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 =&lt;&gt;) {
      chomp;
      s/\r//g;
      my @f = split(/\|/, $line);
      my $i;
      $hour = substr($f[0],11,2);
  
      for ($i==0;$i&lt;=100; $i++) {
          if (($f[$i]=~m/CBAL/) &amp;&amp; ($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 &lt;= 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 &lt;= 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 &lt;= 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/) &amp;&amp; ($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 &lt;= 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/) &amp;&amp; ($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 &lt;= 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,&lt;300 ms,&gt;300 ms\n";
  unless(%CheckBal){
      print "No record found for STCK\n";
  }
  foreach (sort keys %CheckBal){
      print $_.",".$CheckBal{$_}."\n";
  }
  </code></pre>
  
  <p>Current Output:</p>
  
  <pre><code>Balance Check
  Hour,Task,Total Transactions,Total Processing Time/ms,Average TPS/ms,&lt;300 ms,&gt;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
  </code></pre>
  
  <p>Desired Output:</p>
  
  <pre><code>Balance Check
  date,Hour,Task,Total Transactions,Total Processing Time/ms,Average TPS/ms,&lt;300 ms,&gt;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
  </code></pre>