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

前端之家收集整理的这篇文章主要介绍了使用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,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";
	}
}

猜你在找的Perl相关文章