Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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

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)

In reply to Parse mailing addresses with a regex by data67

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (4)
    As of 2021-02-28 07:23 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found