?
Solved

Perl is writting \n as CRLF.  Why?

Posted on 2004-09-16
6
Medium Priority
?
1,007 Views
Last Modified: 2008-03-04
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
0
Comment
Question by:countytechnologies
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 6

Accepted Solution

by:
holli earned 2000 total points
ID: 12073535
\n stands for the standard newline depending on the os.

unix -> \x0A
dos/win -> \x0D\x0A
mac -> \x0D
0
 

Author Comment

by:countytechnologies
ID: 12073595
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.

0
 

Author Comment

by:countytechnologies
ID: 12073692
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.



0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:holli
ID: 12074334
open OUT, ">test";
binmode OUT;
print OUT "\x0A";
0
 
LVL 4

Expert Comment

by:divt
ID: 12076495
Did the result get converted by other intermediary functions/browsers/objects/functions?

Doing what holli suggest can identify this.

0
 
LVL 8

Expert Comment

by:davorg
ID: 12082305
All of these issues are covered in detail in the "perlport" manual page.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question