Hi,
Assuming you've parsed your CSV file and are just looking for the phone number
which is in a string...
If your telephone numbers are north-american only, then the problem is fairly
trivial because you always have the same pattern for numbers (if people did not
throw in extention numbers, that is).
If on the other hand you have non-[Canda/US/Mexico] numbers, then your task
will be *much* harder considering that you are using free-text (human-input
data).
For North American (country code 1) phone numbers:
#!/usr/bin/perl
#1/ isolate the number and drop out all non-numeric data
#Isolate country, area, and telephone for country code 1.
#caution, this will not work outside country code.
#for a rigorous treatment, you have to take into account the extensive range of
#patterns including varying area and telenphne number lengths in some countries
my $text = '1-234 -555-12.12';
print "\n",$text,"\n";
my $country = 1;
$text =~ s/\D//gs;
#2/ you know that in country code 1, all telephone numbers are 7-digit plus 3-
digit area code.
$text =~ /^(\d*)(\d{7})$/;
my $area = $1;
my $number = $2;
#3/ you know that area codes are 3-digits
if ($area =~ /^($country)(\d{3})$/) {
$country = $1;
$area = $2;
}
#done.
print "\nCountry:",$country,"\nArea:",$area,"\nNumber:",$number,"\n";
Output:
---------- perl ----------
1-234 -555-12.12
Country:1
Area:234
Number:5551212
Normal Termination
Output completed (0 sec consumed).
I hope it helps.
Ronan.
RO IT Systems GmbH
Zurich, Switzerland
www.roitsystems.com
www.roasp.com
Quoting [EMAIL PROTECTED]:
> Hello,
>
> I have a some data files in different formats that I want to parse into one
> file under a new standard format.
>
> The different formats are below:
>
> Format 1)
> Vanderbilt,MI,9899660005,P,"Vanderbilt1 MI, US","Vanderbilt MI,
> US",9899660005
> Format 2)
> Calgary,AB,403-770-4904,N
> Format 3
> Anniston,AL,256,2412285,A
>
> Now format 3 is how I want to parse them all and lay them out as:
> city,state,areacode,number,list
>
> My main problem is not format 3, but how do you seperate the areacodes from
> the other format?
>
> Ex: Format 1) areacode and phonenumber is all one 9899660005 and I want it to
> be 989,966-0005
> Format 2) areacode and phonenumber is seperated by - and I want
> 403-770-4904 to be ,403,770-4904
>
> I have jiggled code around and at a loss here :( Any help would be
> appreciated.
>
> Thank You,
> John
>
_______________________________________________
Perl-Unix-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs