in reply to Report parsing

Because both the start and the end markers for the section have the word "region", you'll have to work a little harder to catch the boundaries. You could so it this way ..
if ( /REGION/ ) { if ( /TOTAL/ ) { # Finish with that section } else { # Start with that section } } else { # Regular data line .. handle normally (see below) }
That's something that reads pretty well. Then, I'd probably use a hash to store how region numbers map to different arrays:
my %SalesReps = { 7A => \@steve, 7 => \@sue, 8 => \@mike };
So when you're starting a Region, pick the appropriate array from the hash ..
my $ThisArray = $SalesRep{ $region }
and when you get to the code where you're handling a regular data line, use that array reference to unshift the data into the array.
unshift ( @{ $ThisArray }, $region, $reg_num, @name );

What I haven't done here is catch errors where the region number doesn't match anything in the hash -- it's important to add that code in.

Update: I'm not sure why you print the array after each record .. it seems to me that you'd get record 1, 1-2, 1-3, 1-4 and so forth. Why not wait till the end of the input file to do that? Better yet, write the data to three output files .. less memory usage that way.

--t. alex

"Of course, you realize that this means war." -- Bugs Bunny.

Replies are listed 'Best First'.
Re: Re: Report parsing
by Dalin (Sexton) on Jan 24, 2002 at 20:45 UTC
    The prints were my tests to make sure I was grabbing the appropriate lines. I'll try what you have offered and get back to you. Thanks Where ever there is confusion to be had... I'll be there.