Hello, I have a file starting with:

fixedStep chrom=chrX start=1 step=1 0.930

0.955

0.972

0.985

0.993

0.995

0.994

0.990

0.984

0.971

0.942

0.944

0.971

fixedStep chrom=chrX start=200 step=1

0.987

The problem is that, apart from the numbers shown, there are these headers found in the file multiple times. I want to construct a program that stores the position and the value, that means:

1 0.930

2 0.955

etc

the numbering starts from where it is indicated by the number stored in the field start, that is start = 200 etc...So this means:

200 0.987

etc

I have constructed the following code:

#!/usr/bin/perl -w print "Please enter the filename of your file: "; $dnafilename = <STDIN>; chomp $dnafilename; unless ( -e $dnafilename) { print "File \"$dnafilename\" doesn't seem to exist!!\n"; exit; } unless ( open(DNAFILE, $dnafilename) ) { print "Cannot open file \"$dnafilename\"\n\n"; exit; } while ( <DNAFILE> ) { next if (/fixedStep chrom=chrX start=(.+) step=1/); $counter = $1; } print "$counter\t$_\n"; close DNAFILE; exit;

With awk, we could do it easily with the command: nawk -F' =' 'NF>1{start=$5;next}{print start++,$0}' myFile but I need a program...Any help would be greatly appreciated :)


In reply to How to continue numbering after a regular expression has been found by jpoldot

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.