Extract range of lines from a text file



This is driving me nuts.

I'm walking through a mailbox file, and want to pull out specific lines from each message. The body of each message is in a similar format, having been generated by a script.

I'm doing OK except for one particular block of lines, the customer address data. There is a blank line before and after this block. Example:

Transaction Time: 18:45:55

Amer Neely
POB 1481 Station Main
North Bay ON
P1B 8K7
CANADA

123-456-7890

I've managed to get the 5 lines into a string using this code:

while <IN>
{

# bunch of other comparisons deleted

if (/^Transaction Time:/ ... /^\d\d\d-\d\d\d-\d\d\d\d$/)
{
$CustData = $_;
$CustData =~ s/^Transaction Time:.+//; # lose the beginning pattern
$CustData =~ s/^\d\d\d-\d\d\d-\d\d\d\d$//; # lose the ending pattern
next if ($CustData =~ m/^$/); # skip the blank lines
$CustData =~ s/\n//g; # get rid of blank lines. don't think this working
print "\t$CustData\n";
}
}
close IN;
print "\nAll done.\n";

The problem seems to be that $CustData holds all 5 lines. I need to break out each of the lines into a separate string variable so as to populate a database field. This is what has me stumped. Sure would appreciate some light on this.

--
Amer Neely
.



Relevant Pages