我正在尝试读取包含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($_);
}
我做错了什么?
答案 0 :(得分:1)
chomp您的意见:
open(my $in, "<", "ips.txt") or die "can't open the file $!";
my @lines = <$in>;
chomp @lines;