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.


In reply to Re: Report parsing by talexb
in thread Report parsing by Dalin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.