Link to home
Start Free TrialLog in
Avatar of countytechnologies
countytechnologies

asked on

Perl is writting \n as CRLF. Why?

I thought that \n represented just a line feed character.
Why does the following program result in outputing a CR LF pair, rather than just the LF.

#!/usr/bin/perl
print "\n";

I'm using Active Perl on XP.  I wondered if there was an environment variable I had to set to force Perl to treat \n as just a LF?

Thanks
Gary
ASKER CERTIFIED SOLUTION
Avatar of holli
holli

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of countytechnologies
countytechnologies

ASKER

But even

print "\x0A";

outputs a \x0D\x0A pair.

How can I output just the \x0A running on a DOS system?
Maybe the print command is not the way to do it.

Ultimately, I am trying to replace all the \r\n pairs in a file with just \n but I seem to be unable to write out just the \n character or even get the \n to be written in a search and replace (e.g. $string =~ s/\r\n/\n/g;), presumably because of the OS dependancy.



open OUT, ">test";
binmode OUT;
print OUT "\x0A";
Did the result get converted by other intermediary functions/browsers/objects/functions?

Doing what holli suggest can identify this.

Avatar of Dave Cross
All of these issues are covered in detail in the "perlport" manual page.