Solved

Perl is writting \n as CRLF.  Why?

Posted on 2004-09-16
6
995 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
6 Comments
 
LVL 6

Accepted Solution

by:
holli earned 500 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

863 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now