note
Kenosis
<p>Consider the following instead:</p>
<c>
use strict;
use warnings;
use autodie;
open my $FILE1, '<', 'input.txt';
open my $FILE2, '>', 'output.txt';
while (<$FILE1>) {
s/^HDR.{47}|FTR.+//;
print $FILE2 $_;
}
close $FILE1;
close $FILE2;
</c>
<ul>
<li><c>autodie</c> will trap the file i/o errors (you're not handling these, but you should)</li>
<li>Use only lexical (<c>my</c>) file handles</li>
<li>Use <c>while</c> to iterate through the file</li>
<li>The two substitutions were combined into one</li>
</ul>
<p>If <c>FTR</c> marks the footer to the end of the line, you can just use <c>FTR.+</c> to remove it, since in your example there were only 30 characters left--including <c>FTR</c>. However, it's certainly OK to use <c>FTR.{27}</c>, if you prefer.</p>
1076973
1077029