3 use FS::UID qw(adminsuidsetup dbh);
6 use Locale::SubCountry;
8 my $fsuser = shift @ARGV or die $usage;
9 my $path = shift @ARGV or die $usage;
11 adminsuidsetup($fsuser);
12 local $FS::UID::AutoCommit = 0;
15 #horribly inefficient but you only have to do it once
17 my $world = Locale::SubCountry::World->new;
18 foreach my $countrycode (qw(US CA MX)) {
19 my $c = Locale::SubCountry->new($countrycode);
20 next if !$c->has_sub_countries;
21 $state_to_country{uc $_} = $countrycode foreach $c->all_full_names;
23 my %name_to_country = $world->full_name_code_hash;
27 or die "couldn't open $path\n";
29 my ($npa, $statecode, $statename, $desc) =
30 /^(\d{3}) ([A-Z]{2}) ([\w\s]*\w) \(([^)]*)\)/;
32 warn "couldn't read $_";
35 my $countrycode = $state_to_country{uc $statename} ||
36 $name_to_country{uc $statename};
38 warn "couldn't find country for $statename\n";
42 my $areacode = FS::areacode->new({
44 'state' => $statecode,
45 'country' => $countrycode,
46 'description' => $desc,
48 my $error = $areacode->insert;
53 print "$npa => $statecode, $countrycode\n";