user96492
user96492

Reputation: 11

Geo::IP module does not return all country codes

I'm trying to read a file containing IP addresses and then pass them to Geo::IP to look up their country code, but my code only returns the country code for the last IP in the file.

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($_);
}

What am I doing wrong?

Upvotes: 1

Views: 339

Answers (1)

toolic
toolic

Reputation: 62236

chomp your input:

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

Upvotes: 1

Related Questions