I am not sure what your question really is. You are modifying @current_columns but you are keeping $current_line unmodified and store it in $previous_line for further processing. Do you want your modifications reflected in $previous_line in the next iteration of your loop? If that is the question, you should really store the array @current_columns instead of $current_line, e.g.
my $previous_line = <IN>; chomp $previous_line; my @previous_columns = split(" ", $previous_line); while (my $current_line = <IN>) { chomp $current_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; print OUT "$current_columns[2]\n"; @previous_columns = @current_columns; }
Not tested...
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 hdb
in thread How to loop over two lines, alter a value in the current line and save it to the previous line?
by rjc33
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |