zoukankan      html  css  js  c++  java
  • Perl 按地区统计访问次数

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

  • 相关阅读:
    毕业进度10
    毕业进度9
    毕业进度8
    毕业设计7
    毕业设计6
    java算法每日一练2021/1/26
    java算法每日一练2021/1/23
    java算法每日一练2021/1/21
    java算法每日一练2021/1/20
    java算法每日一练2021-01-18
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13351803.html
Copyright © 2011-2022 走看看