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


$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";
	}
}


 
 
 
发布了80 篇原创文章 · 获赞 33 · 访问量 47万+

猜你喜欢

转载自blog.csdn.net/tower888/article/details/17303389