in reply to substitutions on a single line
$. == 1 && $aa =~ /LEU\b/ && s/ (.*)/$z31eu $z2leu $z1leu $1/;
That way, only when $. (the filehandle line counter) equals zero (the first line of the file) you will actually modify the line. The rest of your iterations through the fils you'll basically skip the code that performs the substitution.
Remember, of course, that you do have to write each line anew. The most common strategy is to open the input file, open a temporary output file, read line by line from the input file as you write line by line to the output file. You must do this for every line of the file. And on the first line (in your case) you'll also perform additional modifications to the data. Finally, you close both files, and rename the temp file to the name of your input file.
Update: Changed $. == 0 to $. == 1 to correct the error pointed out by halley.
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: substitutions on a single line
by halley (Prior) on Apr 13, 2004 at 18:10 UTC | |
|
Re: Re: substitutions on a single line
by Anonymous Monk on Apr 14, 2004 at 13:02 UTC | |
by davido (Cardinal) on Apr 14, 2004 at 16:40 UTC |