Greetings,
First some suggestions, against using barewords, and for using open in its three terms form: more explicit and understandable
Also I put there use autodie because I'm lazy :$

use warnings; use strict; use autodie; open my $in,'<', "in.txt"; open my $out,'>', "out.txt";
Since you start at first line and then jump over each line to save to the previous line you can use the perl auto variable for line counts
my $previous_line; while (<$in>) { $current_line = $_; chomp $current_line; if(!defined($previous_line) || $. mod 2 != 0){ $previous_line = $current_line; next; } my @previous_columns = split(" ", $previous_line); my $end_coor = $previous_columns[2] + $previous_columns[3]; my @current_columns = split(" ", $current_line); my $seq_length = length $previous_columns[6]; my $gap_count = $previous_columns[6] =~ tr/Q//; my $original_length = $seq_length - $gap_count; my $original_end_coor = $previous_columns[2] + $original_length; my $distance = $current_columns[2] - $original_end_coor; $current_columns[2] = $end_coor + $distance; $previous_line = $current_line; print $out "$current_columns[2]\n"; } close $in; close $out;
I'm not sure about the way you want to go over the file though, do you want to just jump over half of the lines?


In reply to Re: How to loop over two lines, alter a value in the current line and save it to the previous line? by QuillMeantTen
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.