Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-20 15:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found