in reply to How to continue numbering after a regular expression has been found

Your assignment to $counter is never executed at the right time because you do a next before it gets encountered. And if the 'if' is false, there shouldn't be an assignement to $counter but an increment. You probably want this:

while ( <DNAFILE> ) { if (/fixedStep chrom=chrX start=(.+) step=1/) { $counter = $1; next; } print "$counter\t$_\n"; $counter++; close DNAFILE;

Code is untested.

  • Comment on Re: How to continue numbering after a regular expression has been found
  • Download Code

Replies are listed 'Best First'.
Re^2: How to continue numbering after a regular expression has been found
by jpoldot (Initiate) on Feb 11, 2011 at 12:49 UTC
    Thank you very much...This works for me...Is there any way that I can store all these values into 2 arrays, one having the counter and the other the corresponding actual values???

      There is even an easy way :-)

      push the $counter to one array and the $_ to another instead of (or after the) print

      Rata