Perl 按地区统计访问次数

Perl 按地区统计访问次数,第1张

概述#!/usr/local/bin/perluse LWP::Simple qw(get);use Encode;use Encode::CN;use JSON; use URI::Escape;open (LOG ,"<","129_2");while (<LOG>){$ip = $_;print "hostip is $_\n";$host = "http://ip.t
#!/usr/local/bin/perluse LWP::Simple qw(get);use Encode;use Encode::CN;use JsON; use URI::Escape;open (LOG,"<","129_2");while (<LOG>){$ip = $_;print "hostip is $_\n";$host = "http://ip.taobao.com/service/getIpInfo.PHP?ip=$_";$content = get($host);$content =~ s/\u([0-9a-fA-F]{4})/pack("U",hex())/eg;  $content=encode(gbk,$content);if ($content =~ /(.*?)"region":(.*?),"region_ID"(.*?)"city":(.*?),(.*?)/){    $a = ;   $b = ;   $a =~ s/"//g ;   $b =~ s/"//g ;if ($b ){$city = $b;}else{   $city = $a;};   $city =~ s/"//g ;    print "$city is $city\n"; }    open (B,">>x.log");    print B ("$city  $ip\n");   print "$content\n"}; open (LOG,"x.log");                      while (<LOG>) {                      chomp;  		     $var= (split / /,$_)[0]; 		     $log{$var}++;                      }		    while(my($city,$times) = each %log) {                           print "$city  $times\n";			 open (C,">>y.log");			 print B ("$city  $times\n");                              }  
总结

以上是内存溢出为你收集整理的Perl 按地区统计访问次数全部内容,希望文章能够帮你解决Perl 按地区统计访问次数所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1273837.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存