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