Solved

Perl is writting \n as CRLF.  Why?

Posted on 2004-09-16
6
991 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
Comment Utility
\n stands for the standard newline depending on the os.

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

Author Comment

by:countytechnologies
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 6

Expert Comment

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

Expert Comment

by:divt
Comment Utility
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
Comment Utility
All of these issues are covered in detail in the "perlport" manual page.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 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

10 Experts available now in Live!

Get 1:1 Help Now