Here is a simple run-down of a suitable approach:
-
Carefully read all of the perldocs that just have been pushed at you. Also get to know the CPAN library and the various modules that are listed there. Your goal should be to have to do as little original work as possible. Actum Ne Agas: “Do Not Do A Thing Already Done.” You did not get an “RTFM” brush-off response.
-
Your code will read the file line-by-line, using a regular expression (or split) to divide the line into two parts. The left part is the keyword; the right part is the value.
-
As you read each line, you will accumulate the (keyword, value) pairs. A hash is the most-loigical way to do this.
-
Although all the lines seem to look alike, there is one kind of record which will identify “the start of something new,” such that an output-record needs to be written (and previously accumulated values discarded so that you do not hang on to “stale data”) before starting to capture the new record.
-
When the file-reading loop ends, if there are any accumulated values, a final output-record needs to be written for these, as well. (Repeated tasks such as “writing the output record” are a logical place to use a sub.)
-
When writing programs like these, I like to be defensive. I like to think that the file-reading program ought to be the one that detects that “this input file is bogus,” if it is, since this program is clearly in the best position to do so. (So, “if the program ran successfully, the contents of the file are more-or-less good.”)