sub pull_country_code {
# Given a string of digits, pull a matching country code
# from the beginning and return the resulting code and
# remaining digits.
my $number = shift;
return unless $number;
croak "Non numeric data\n" unless $number =~ /^\d+$/;
my @digits = reverse split(//,$number);
my @pulled;
my $ptr = \%Icodes_huff;
while (@digits) {
$_ = pop @digits;
last unless $ptr->{$_};
push(@pulled, $_);
$ptr = $ptr->{$_};
last unless ref $ptr;
}
my $cc = join('', @pulled);
my $left = join('', reverse @digits);
return $number unless $left =~ /\d/;
return($left, $cc);
}