http://www.perlmonks.org?node_id=268165

data67 has asked for the wisdom of the Perl Monks concerning the following question:

Background
I am trying to read a flat file that contains some name and address information. Now whats making this tricky is that this file is not delimited by anything.

Heres an example:

141 Martha Lynn Amblynoster 12345 New Pickle Drive MoreTown PA 98765 6 +54 555-1212 no detail 178 Edgar Bimblybum Jr. 23456 Highfiddle Road Acheville Ma 24680 345-7 +89-1234 no detail 161 Joyce W. Wogerbung 18 Lily Piffle Lane Middleton PA 34567 610-678- +2345 no detail 188 Alex Shmogle 6543 Bibblyboo St NW Apt B Washington DC 20009 202-98 +7-6543 no detail

Problem
I was trying to read the file in to an array and then going through each line and trying to pull out each section of information.
Namely, Name-CustomerName-CustomerAddress(broken down in: Street_City_State)-Telephone-Comments.

Here is what i have so far:

foreach my $line (@data_file) { if ($line =~ m!^(\d+)\s+(([A-Za-z]+\s+[A-Za-z].\s+[A-Za-z]+)|( +[A-Za-z]+\s+[A-Za-z]+) )!) { print "$1 - $2 \n"; $custNum = $1; # First number field. $custName = $2; # Name styles can vary + so match everything between two numbers. $custStreet = $3; # Street is everything + after name and before CITY. $custCity = $4; # City is after addres +s and before the TWO char state identifier. $custState = $5; # State is after addre +ss and before FIVE digit zip number. $custZip = $6; # Zip is before teleph +one number and after State id. $custTel = $7; # Telephone no. is aft +er zip and before comments field. $custComments = $8; # Last remaining part +after telephone number. } }

The regex you see above so far matches the CustName and some names. Other than that i still am trying to figure this one out. Any help will be great.Thx.

Obfuscated data - dvergin 2003-06-23

edited: Tue Jun 24 01:28:48 2003 by jeffa - title change (was: Help with Regular Expression)