jb60606 has asked for the wisdom of the Perl Monks concerning the following question:
Using the timestamp in the second column as the key, I need to search for any line containing a "Pending=" queue greater than a user specified amount, and add it to an array. Also, if there was a "Gap" detected at the same second (I'll be stripping the milliseconds), add them to the array for that same time stamp. In the text above, each key/array pair to read like:2011-04-03 09:37:12.129 (INFO, ICELineHandler.cpp:339) Product Def Mar +ketID 90120253, Symbol 'BRN FMU0012_OMCA0000118502081312' <b>2011-04-09 21:32:15.525 [3509,3523]: Gap detect on 233.156.208.41:2 +0041 from 2746318 to 2746373, moving to next message 2011-04-09 21:32:15.585 [3509,3523]: Gap detect on 233.156.208.41:2004 +1 from 2746420 to 2746475, moving to next message 2011-04-09 21:32:15.639 [3509,3522]: Received data on Connection[ICE-O +ptions]. Pending=214044. </b> 2011-04-03 09:37:12.129 (INFO, ICELineHandler.cpp:339) Product Def Mar +ketID 90120253, Symbol 'BRN FMU0012_OMCA0000118502081312'
Thus far, I have the following code, but it doesn't seem to work. Any recommendations?my %ICE = ( 21:31:10 => [ 'Pending=3201', ], 21:32:14 => [ 'Pending=1000', ], 21:32:15 => [ 'Gap detect', '233.156.208.41:20041', 'Pending=21404 +4',], 21:32:24 => [ 'Gap detect', '233.156.208.41:20041', 'Pending=10400 +0',], 21:32:58 => [ 'Gap detect', '233.156.208.41:20041' 'Pending=96000' +,], 21:33:12 => [ 'Pending=528', ] ); And print comma separated: 21:31:10, Gap detect 233.156.208.41:20041, Pending= 21:31:12, Gap detect 233.156.208.41:20041, Pending=3400
UPDATE: Apologies for the "half-arsed" description and lack of presentation of the results I'm getting. I wrote this in a hurry, thinking I could update it when I got home. Being new here, I didn't expect so many quick responses. I'll update the post shortly. Thanks for your help
# Get today's date which will be used as the default. my($day, $month, $year) = (localtime)[3,4,5]; $month = sprintf '%02d', $month+1; $day = sprintf '%02d', $day; $year = $year+1900; $ymd = "$year-$month-$day"; my $total; # variable to be used for queue total for the given timefra +me my $count = 0; ## Get command line arguments, convert time to seconds ##my $logFile = "pmmd-ltc-fsrlabs21-mdrc-server-cta.log"; my $logFile = "pmmd-ltc-fsrlabs41-mdrc-server-ice.log"; my $sTime= $ARGV[0]; my @sTime=split(/:/,$sTime); # split start time my $sSecs=$sTime[0] * 3600 + $sTime[1] * 60 + $sTime[2]; # convert sta +rt-time to seconds my $eTime = $ARGV[1]; my @eTime=split(/:/,$eTime); # split end time my $eSecs=$eTime[0] * 3600 + $eTime[1] * 60 + $eTime[2]; # convert sto +p-time to seconds my $tHold = $ARGV[2]; open(LOG, "$logFile") or die "Couldn't open file for processing: $!"; while ( $line = <LOG> ) { unless (($data[10] =~ m/Pending=/) || ($data[6] =~ m/Gap/)) { next; } +# skip elements we don't want if ($line =~ m/Pending=/) { my @data=split(/ /,$line); # split the line up $data[10] =~ s/[A-Za-z=.]//g; # delete "Pending", "=" and "." $data[1] =~ s/\..*//g; # delete the millisecond element of the + (line)lTime var my @lTime=split(/:/,$data[1]); # split the line time my $lSecs=$lTime[0] * 3600 + $lTime[1] * 60 + $lTime[2]; # con +vert line-time to seconds if (($data[0] eq $ymd) && ($data[10] >= $tHold) && ($lSecs >= +$sSecs) && ($lSecs <= $eSecs)) { $line = "$data[1],$data[10]"; } } elsif ($line =~ m/Gap detect/) { my @data=split(/ /,$line); # split the line up $data[1] =~ s/\..*//g; # delete the millisecond element of the + (line)lTime var my @lTime=split(/:/,$data[1]); # split the line time my $lSecs=$lTime[0] * 3600 + $lTime[1] * 60 + $lTime[2]; # con +vert line-time to seconds if (($data[0] eq $ymd) && ($lSecs >= $sSecs) && ($lSec +s <= $eSecs)) { $line = "$data[1],$data[9]"; } } else { next; } ($time, $rest) = split ',', $line, 2; #$time =~ s/\..*//g; # delete the millisecond element @fields = split ',', $rest; $HoA{$time} = [ @fields ]; } for $time (sort (keys (%HoA)) ) { print "$time: @{ $HoA{$time} }\n"; } close LOG;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Help with hash of arrays from file
by ww (Archbishop) on Apr 10, 2011 at 18:01 UTC | |
Re: Help with hash of arrays from file
by GrandFather (Saint) on Apr 10, 2011 at 23:29 UTC | |
Re: Help with hash of arrays from file
by luis.roca (Deacon) on Apr 10, 2011 at 23:21 UTC | |
Re: Help with hash of arrays from file
by toolic (Bishop) on Apr 11, 2011 at 01:19 UTC | |
Re: Help with hash of arrays from file
by Khariton (Sexton) on Apr 10, 2011 at 18:56 UTC | |
by GrandFather (Saint) on Apr 10, 2011 at 20:46 UTC |