[NTLUG:Discuss] perl question
Fred James
fredjame at concentric.net
Wed Jun 4 12:42:25 CDT 2003
I don't know a lot about Perl, so I may be speaking out of turn, but if
every record is guaranteed to have five lines (no more and no less),
even when some lines/fields are "empty", and every line is terminated
with a newline character, there should be a way to approach this. The
first four fields, being one line each, should have to be assumed to
contain any or no printable characters and therefore the delimiter is
the newline character. The last three fields appear together in the
last line. If one may assume a comma will always separate the first
field from the rest of the line, all that is left is to grab the last
field of the line and check it for numeric. That is, if it is numeric
we can consider it the zip code - otherwise it is the state. I believe
that would be fine as long as all addresses are within the USA, and I
will assume that to be true because the address record does not have a
field for country. One last wrinkle - what are the possibilities within
the zip code field? nnnnn, nnnnn nnnn, nnnnn-nnnn, nnnnnnnnn. So, it
may be necessary to consider the last two "words" of the last line, and
the characters 0-9, and -, in the testing to determine what is the zip
code, if any. I do not know of any state where the name contains a
numeric character so I believe that would work.
MadHat wrote:
>On Wed, 2003-06-04 at 10:43, Bobby Wrenn wrote:
>
>
>>On Wed, 2003-06-04 at 09:52, Michael Patrick wrote:
>>
>>
>>>On Wed, Jun 04, 2003 at 09:49:02AM -0500, Bobby Wrenn wrote:
>>>
>>>
>>>>I have a text file in the following format:
>>>>
>>>>name1
>>>>[name2]
>>>>address1
>>>>[address2]
>>>>city, state [zip]
>>>>
>>>>
>>>>
>>>How is the next record done? Is there a space between them so you could read each line then we you hit a blank line you'll know city, state [zip] was the preceding line?
>>>
>>>Michael
>>>
>>>
>>>
>>Each line is terminated with a <cr>. There are no blank lines between
>>records,
>>
>>
>
>Unless you can guarantee that the name field will never have a comma (,)
>and you can guarantee that the city/state field will, you are in a
>pickle.
>
>Like is someone is 'Richard Cranium, Jr', then you couldn't use the
>existence of the comma to determine the end of each record. Or even
>matching on a word followed by a comma then 2 characters.
>
>
--
never underestimate the value of backups
More information about the Discuss
mailing list