All pastes #641179 Raw Edit

Someone

public text v1 · immutable
#641179 ·published 2007-07-31 23:52 UTC
rendered paste body
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);
}