I am writing a Perl program to add \r \n as the 201st and 202nd bytes at the end of a 200 byte record. I am trying to do that this way:
use constant REPORT_LINE_LEN => 200;
while(($rc = read $infile, $report_line, REPORT_LINE_LEN(), 0) != 0)
{
chomp $report_line;
$report_line .= "\r\n" . "\n";
print $outfile $report_line;
}
The carriage return ^M character is at position 201, and I need a \n at 202, but can't seem to get it placed there without increasing the record's length over 202 bytes. I am verifying the location of the ^M with vim, which indicates the file is still in Unix format.
I have searched a lot of sources out there, and am stumped. Any help would be appreciated including what how the last two bytes might appear in vim.
I am confirming the record length in vim by pressing '$' to get to the end of the line. Right now, it says 201. I'm also using head -n 1 rmvtape.out | wc -c
to confirm the length of the record where rmvtape.out
is the file containing these records. The length is 202
.
So, is the ^M invisible in vim in this case?
$report_line .= "\r\n" . "\n";
You are adding three characters here, e.g \r
,\n
and another \n
.
Omit the last \n
and everything should be fine, e.g.:
$report_line .= "\r\n";