That's something that reads pretty well. Then, I'd probably use a hash to store how region numbers map to different arrays:if ( /REGION/ ) { if ( /TOTAL/ ) { # Finish with that section } else { # Start with that section } } else { # Regular data line .. handle normally (see below) }
So when you're starting a Region, pick the appropriate array from the hash ..my %SalesReps = { 7A => \@steve, 7 => \@sue, 8 => \@mike };
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.my $ThisArray = $SalesRep{ $region }
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.
In reply to Re: Report parsing
by talexb
in thread Report parsing
by Dalin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |