Perl和Geo :: IP模块

时间:2013-07-12 13:06:49

标签: perl

我正在尝试读取包含IP地址的文件,然后将它们传递给Geo :: IP以查找其国家/地区代码,但我的代码仅返回文件中最后一个IP的国家/地区代码。

open(my $in, "<", "ips.txt") or die "can't open the file $!";
my @lines = <$in>;

use Geo::IP;
my $gi = Geo::IP->new(GEOIP_MEMORY_CACHE);
foreach (@lines) {

print $gi->country_code_by_addr($_);

}

我做错了什么?

1 个答案:

答案 0 :(得分:1)

chomp您的意见:

open(my $in, "<", "ips.txt") or die "can't open the file $!";
my @lines = <$in>;
chomp @lines;