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.

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?

Who is Participating?
holliConnect With a Mentor Commented:
\n stands for the standard newline depending on the os.

unix -> \x0A
dos/win -> \x0D\x0A
mac -> \x0D
countytechnologiesAuthor Commented:
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.

countytechnologiesAuthor Commented:
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.

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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.

All of these issues are covered in detail in the "perlport" manual page.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.