[NTLUG:Discuss] perl question

David Camm dcamm at advwebsys.com
Wed Jun 4 10:37:39 CDT 2003


in order to process multi-line 'records' the easiest thing to do is to leave a 
blank line between records and set $/ = ""; to put perl in 'paragraph mode'

then:

while (<I>) {$_ will contain all the lines in the record ......}

if i read your description correctly, the name2 and address2 lines might be 
missing. it would be MUCH easier if the program that created this file used a 
special character at the beginning of the line (say !) to indicate absence of data.

then you could say:

while (<I>) {
	@lines = split(/\n/);
	foreach $l (@lines) {if ($l =~ /^\!/) {next;} else {process ..}}
}

it's easy to determine if the zip code is present.

david camm
advanced web systems






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 
> 
> _______________________________________________
> https://ntlug.org/mailman/listinfo/discuss
> 





More information about the Discuss mailing list