您的位置:首页 > 其它

使用perl统计日志中单位时间内的请求数

2013-12-13 15:51 465 查看
$file="g:/log/x.log";
%map=();
open(IN,"<$file") || die "Couldn't open $filename for reading: $!";
$num=0;
$v=0;
$str="";
while($line=<IN>)
{
if (!($line=~m/.*logid.*phonenumber.*message.*/)) {#不匹配就继续循环
next;
}
#print $line."\n";
$str=substr($line,0,20);#cut str

if(exists ($map{$str}))
{
$v=$map{$str};
$v++;
$map{$str}=$v;
}else{
$map{$str}=1;
}

#print $str."===".$map{$str}."\n";
}

close($IN);

while (($key, $value) = each(%map) ) {
if($value>40){
print "$key ------$value "."\n";
}
}




                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: