in reply to count the occurrence of second line of a paragraph in a file

welcome to the monastery umaykulsum,

you put some effort formatting your questio and showing your attempt, but if i can ask for more, try to show some simplified data; infact having AAAA and ABAA instead of 160 chars line is the same problem.

That said, i notice a first error: you are, for each file to read, reopening also the output one using the mode > which will overwrite the file each time. Put the opening of the output file outside of the loop. Also Perl is smart enought to close filehandels for you (wwhen they go outside of a scope) but is better check the open and close filehandles explicitly. Second you are setting $/ to null enabling the so called slurp mode. Doing you influence what Perl see as line, becoming different from what you call a line.

Finally perhaps i dont understand your question clearly: why you want 4 lines to be printed? why the paragraphs which second line starts with TACAG must be associated to the (header?) line that contains 20279 and not with the one containing 18609 ?

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^2: count the occurrence of second line of a paragraph in a file
by choroba (Cardinal) on Apr 29, 2016 at 07:15 UTC
    > which will overwrite the file each time

    It's a different file every time (and, as the code is written now, one single time).

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
      ah, right! you are correct!

      L*

      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.