[EMAIL PROTECTED] wrote: > 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.
Assuming you already have determined the format (untested code for example): if ($format1 or $format2) { my @f1 = split /\s*,\s*, $_; # assumes line is in $_ $f1[2] =~ tr/-//d; # drop -'s for format2 my @f2 = ($f1[0], $f1[1], substr ($f1[2], 0, 3), substr ($f1[2], 3, 3), substr ($f1[2], 6, 4)); print join ',', @f2; print "\n"; } -- ,-/- __ _ _ $Bill Luebkert ICQ=162126130 (_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED] / ) /--< o // // http://dbecoll.tripod.com/ (Free site for Perl) -/-' /___/_<_</_</_ Castle of Medieval Myth & Magic http://www.todbe.com/ _______________________________________________ Perl-Unix-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs