Connecting Tech Pros Worldwide Forums | Help | Site Map

Trouble with printing newlines to a file

Newbie
 
Join Date: May 2007
Posts: 1
#1: May 12 '07
I want to be able to print just an "LF" to a file.

First, to clear up any ambiguity, I'm going to call the ASCII character with a hex code of 0A and a decimal code of 10 an "LF". I'm also going to call the ASCII character with a hex code of 0D and a decimal code of 15 a "CR".

As a simple test case:

open TEST, ">", "test.data";
select TEST;
print "A" . chr(hex("0A")) . "B" . "\n" . "C" . "\r" . "D";
close TEST;

Logically, when I look at the test.data file with a hex editor I'd expect just a "LF" between the A and B, but instead there are is a "CR" followed by an "LF."

Here is what a hex editor shows is in "test.data" (first line is hex, second line are chars):

41 0D 0A 42 0D 0A 43 0D 44
A CR LF B CR LF C CR D

I was expecting only a "LF" (i.e., 0A) between the "A" (41) and "B" (42) ...

If it helps this is Perl 5.8.8 (ActiveState Perl Build 820) on Windows XP.

Thanks for any advice you may be able to give me.

KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#2: May 12 '07

re: Trouble with printing newlines to a file


already answered on the other forum where you posted this same question: use binmode.
miller's Avatar
Moderator
 
Join Date: Oct 2006
Location: San Francisco, CA
Posts: 830
#3: May 13 '07

re: Trouble with printing newlines to a file


cpan binmode
Reply