Hi, thanks for all your help. I just initially misused the word "cumulate", I'm trying to do exactly what you just quoted in italics but my current code falls just short. I want to alter the value in the 3rd column of each line based on some calculations using values from the same line and the previous line (so that has to be included somehow, although I'm open to completely different ways of doing it). So I want my loop to start on line 2, altering the 3rd column based on other values in line 2 and line 1; the next iteration would then alter the 3rd column of line 3 based on values in line 3 and line 2, and so on. My current code does this, the problem is that whatever is the $previous_line at the time contains the initial values from the file itself, I want it to contain the 3rd column value that I changed in the previous iteration of the loop.

So for example, if in the first 3 lines of the file my 3rd columns are 4, 6, 9. My loop will start on line 2, and say it will change 6 to 8. The next iteration will be on line 3, however when it accesses line 2 it uses the old value 6 when I need it to use the new value 8, and hence from the third line onwards my code gives me incorrect output. So I'm just looking for a way to save the changed value to the previous line for the next iteration of the loop.


In reply to Re^4: How to loop over two lines, alter a value in the current line and save it to the previous line? by rjc33
in thread How to loop over two lines, alter a value in the current line and save it to the previous line? by rjc33

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.