Hello all and Happy New Year!! I only dabble in perl, just enough to be dangerous so hopefully this one isn't out of bounds. I have a bunch of files I need to modify, within each file are multiple sections, here's an example of part of a file.

C 1298 1 28 0
A 1920 1035 10 0 9 3 #=12
I 1284 vtg:CAP 2 2250 1045 0 1 '
A 2285 1035 10 0 3 0 PKG_TYPE=SMC0805
A 2285 1065 10 0 3 3 REFDES=C25
A 2285 1055 10 0 3 3 VALUE=334P
A 2285 1045 10 0 3 3 VOLTAGE=16V
A 2285 1025 10 0 3 1 TOL=20%
C 1309 5 3 0
A 2270 1075 10 0 3 3 #=1
C 1296 3 4 0
A 2270 1045 10 0 3 3 #=2
I 1283 vtg:DRAM 2 2250 985 0 1 '
A 2285 1005 10 0 3 3 REFDES=U23
A 2285 975 10 0 3 0 PKG_TYPE=TQFP144
C 1310 3 4 0
A 2270 985 10 0 3 3 #=2

I need to change the value of PKG_TYPE according to an array I have that lists the new PKG_TYPE values by their REFDES value. Each section I need begins with I and is followed by one or more A lines in no particular order. Not sure where to go with this one. Maybe identify an I-beginning line then put each following A-beginning line into a hash until I hit another character? I've never used hashes before either, be gentle.

Any assistance or direction would be greatly appreciated. Thanx.

In reply to Modify a line following a target line? by djincnj

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.