Solved

Perl is writting \n as CRLF.  Why?

Posted on 2004-09-16
6
1,000 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 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
Technology Partners: 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
use google analytics code in perl script 2 99
Convert grep lines to perl 6 97
Perl Write to Specific line in a file 15 123
Perl tar error 8 72
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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…

738 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