0

我正在尝试读取包含 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($_);

}

我究竟做错了什么?

4

1 回答 1

1

咀嚼你的输入:

open(my $in, "<", "ips.txt") or die "can't open the file $!";
my @lines = <$in>;
chomp @lines;
于 2013-07-12T14:01:33.090 回答