I am having a hard time understanding the logic behind the loop required to parse a file that contains many batches that correlate only with their detail files. To the best of my ability, I have tried to give an example of this issue. The example is as follows:

Each document will consist of the same layout. The first line of the file is the file header (FH) and it contains information regarding the contents of the file. Throughout the document, we will have numerous batch headers (BH). Information contained within the BH is only pertinent to the subsequent 0006 (detail records). There is a correlation between the BH and it's respective 0006 (detail records) The file trailer is indicated by the FT. This contains the record count. For example, I will have to take information from the BH segment and perform regular expressions based upon the content in the detail lines located immediately below the BH. Therefore, the information contained in the BH must be used for the RegExp in the subsequent detail lines. Once all of the detail lines have been read in a specific BH, the process will start over by taking the values from the next BH. The process will be completed once the entire file has been read.

Example File
FH825693963
BH0001000123
0006125 (Translate from BH0001000123)
0006285 (Translate from BH0001000123)
0006387 (Translate from BH0001000123)
0006496 (Translate from BH0001000123)
0006311 (Translate from BH0001000123)
0006423 (Translate from BH0001000123)
BH0001000456
0006585 (Translate from BH0001000456)
0006658 (Translate from BH0001000456)
0006798 (Translate from BH0001000456)
BH0001000789
0006996 (Translate from BH0001000789)
0006587 (Translate from BH0001000789)
FT0000000016

FH: File Header, BH: Batch Header, FT: File Trailer.

I truly appreciate all help that has been given to me in the past. Many thanks in advance for any and all advice.

Lastly, I would like to thank fsn, Bird, dug, anithri, Aristotle, and bronto for their help on my last question. I decided to post another thread because I felt that I did not describe my problem properly.

Thanks again!!!


In reply to Parse File Containing Multiple Batches With Correlating Detail Records by Anonymous Monk

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.