I think your three-step plan is making things more complicated than they need to be. For one thing, the list of labels that you need (assuming that you really do need these) should be stored in a hash. Just figure out what piece of information about each label will make sense in your app as a hash key (i.e. the thing you'd want to use later for looking things up), and what information will be useful (if anything) as a hash value.

Use more than one hash if that makes things easier (but often, a single hash will do).

As for working out how to construct the output file, it would be better, if possible, for the changes to be made and output produced as you're reading the input. For example, if you somehow know that you need to insert a "(LIG O 51 ...)" line and you input a line that has "(LABEL O 52)", do you have enough information at this point to output the line(s) that should precede "(LABEL O 52)" ?

If you need to read the whole input before resolving that sort of problem, that's okay -- but again, it may be better to hold the input data in a suitable structure (AoH or HoA or somesuch) to reduce the risk of scrambling it beyond recognition.

You showed us an "easy" example in the OP, but you haven't given us a clear example of a "hard" case -- what it looks like on input, and what you'd like it to look like on output -- maybe I'm missing something, but this part isn't clear to me based on what you've said so far.


In reply to Re^3: adding lines at specific addresses by graff
in thread adding lines at specific addresses by pindar

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.