first build a hash which record all countries and their codes.
my %countries = (852 => 'Hong Kong', 853 => 'Macau' ...);

then use regex or other ways (I prefer substr) to get the prefix.
my $prefix = substr($string,1,3);

last get the country name via the prefix code.
my $country = $countries{$prefix};

2007/8/27, Mihir Kamdar <[EMAIL PROTECTED]>:
> Hi,
>
> I want to implement longest prefix match in my code in perl, but am not able
> to get started with it. I am sure, it can be easily achieved with the help
> of regex in perl, but I haven't worked on it. Following is what I want to
> do:-
>
> If the phone number is
> +852xxxx ---> The country is Hong Kong
> +853xxxx ---> The country is Macau.
>
> I have a list of 65 such countries and their codes. I have to read a
> particular field in the CSV file, and on the basis of longest prefix match,
> assign a country to it.
>
>
> Thanks in anticipation,
>
> Mihir
>

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to