diff --git a/geoip/xt_geoip_build b/geoip/xt_geoip_build index 511f48e..7699219 100755 --- a/geoip/xt_geoip_build +++ b/geoip/xt_geoip_build @@ -11,7 +11,6 @@ use Text::CSV_XS; # or trade for Text::CSV use strict; my %country; -my %names; my $csv = Text::CSV_XS->new({binary => 0, eol => $/}); # or Text::CSV my $mode = "VV"; my $target_dir = "."; @@ -29,10 +28,9 @@ if (!-d $target_dir) { while (my $row = $csv->getline(*ARGV)) { if (!defined($country{$row->[4]})) { - $country{$row->[4]} = []; - $names{$row->[4]} = $row->[5]; + $country{$row->[4]} = {name => $row->[5], pool => []}; } - my $c = $country{$row->[4]}; + my $c = $country{$row->[4]}{pool}; push(@$c, [$row->[2], $row->[3]]); if ($. % 4096 == 0) { print STDERR "\r\e[2K$. entries"; @@ -43,11 +41,11 @@ print STDERR "\r\e[2K$. entries total\n"; foreach my $iso_code (sort keys %country) { printf "%5u ranges for %s %s\n", - scalar(@{$country{$iso_code}}), - $iso_code, $names{$iso_code}; + scalar(@{$country{$iso_code}{pool}}), + $iso_code, $country{$iso_code}{name}; open(my $fh, "> $target_dir/".uc($iso_code).".iv0"); - foreach my $range (@{$country{$iso_code}}) { + foreach my $range (@{$country{$iso_code}{pool}}) { print $fh pack($mode, $range->[0], $range->[1]); } close $fh;