Oops, serveral typos in the code I gave you. Always use -w ! :-)
#!/usr/bin/perl -w
use Time::Local;
my @now = localtime; my $hour = $now[2];
$now[$_] = 0 for 0..2; # set hour, min, sec to 0;
$daychange = timelocal(@now);
my @dataSUM = <DATA>;
my $sum =0;
my $firststart;
my $laststop;
#my $unixtime;
foreach my $line(@dataSUM) {
my @lineData = split(/[ \t]+/, $line);
my $startime = $lineData[0] if(&is_numeric($lineData[0])) ||
+ die "$lineData[0] not numeric\n";
my $stoptime = $lineData[1] if(&is_numeric($lineData[1])) ||
+ die "$lineData[1] not numeric\n";
# $unixtime = scalar localtime $lineData[1] if(&is_numeric(
+$lineData[1])) || die "$lineData[1] not numeric\n";
my $xover_bytes = $lineData[7] if(&is_numeric($lineData[7])) ||
+ die "$lineData[7] not numeric\n";
my $art_bytes = $lineData[9] if(&is_numeric($lineData[9])) ||
+ die "$lineData[9] not numeric\n";
my $list_bytes = $lineData[11] if(&is_numeric($lineData[11])) ||
+ die "$lineData[11] not numeric\n";
my $newnews_bytes = $lineData[13] if(&is_numeric($lineData[13])) ||
+ die "$lineData[13] not numeric\n";
my $lineSum = $xover_bytes + $art_bytes + $list_bytes + $newn
+ews_bytes;
# $sum += $lineSum;
$sum{ ($daychange >= $stoptime ? 'first' : 'second') } += $lineSum;
$firststart = ($startime < $firststart) || $firststart ==0 ? $star
+time : $firststart;
$laststop = ($stoptime > $laststop ) ? $stoptime : $laststop;
}
map { print "$_ => $sum{$_}\n" } keys %sum;
sub is_numeric {
my $data = shift;
return($data =~ m/^\d+$/);
}
__DATA__
1149621887 1150922348 stormchaser 69.0.0.0 69.0.0.0 NG004193
+@net.NET 3 820 156 1757 0 0 0 0
+ 0 0 176
1149621900 1150922348 stormchaser 69.0.0.0 69.0.0.0 NG004193
+@net.NET 1 648 80 00 0 0 0 0
+ 0 93
1149622376 1150922348 stormchaser 69.0.0.0 69.0.0.0 NG004193
+@net.NET 3 793 243 852 0 0 0 0
+ 0 0 268
1149625677 1150922348 stormchaser 213.0.0.0 213.0.0.0 Sinkbad@
+net.net 1 493 0 00 0 0 0 0
+ 0 1
1149621887 1151008726 stormchaser 69.0.0.0 69.0.0.0 NG004193
+@net.NET 3 820 156 17570249 0 0 0 0
+ 0 0 176
1149621900 1151008726 stormchaser 69.0.0.0 69.0.0.0 NG004193
+@net.NET 1 648 80 00 0 0 0 0
+ 0 93
1149622376 1151008726 stormchaser 69.0.0.0 69.0.0.0 NG004193
+@net.NET 3 7932259 243 85227944 0 0 0 0
+ 0 0 268
Yields:
first => 5363
second => 110731920
cheers,
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
|