Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
go ahead... be a heretic
 
PerlMonks  

Re: CR+LF

by jsprat (Curate)
on Jun 19, 2003 at 02:07 UTC ( #267053=note: print w/ replies, xml ) Need Help??


in reply to CR+LF

Here's a long answer, use one of the following:

  1. Explicitly print your line ending - use chr(13) or "\x0d" or "\015" or "\cM" instead of "\n"
  2. Convert the file from dos2unix using your favorite utility.
  3. In memory, perl sees no "\r\n" - only on output does it get translated. "binmode STDOUT; #any filehandle, not just STDOUT" prevents this translation.
  4. Change the output record separator , and print no explicit line ending, ie $\ = chr(13); print "This is my line"; #no line ending
  5. If the file is transferred by ftp, be sure it is ftp'ed in ascii mode

Short answer - use method 1 if the file is only to be used on *nix platforms. Use 2 if you need the file on both platforms.

HTH...

BTW, more than once I've wished for a command line switch (or configuration variable) to specify the value of the newline character.

Update: I always get cr & lf backwards - is it 10 and 13 or 13 and 10 :(

And thank you Tye for the pointer to your Line Feeds node - printing \0x0A puts a \r\n into the file!


Comment on Re: CR+LF
Select or Download Code
Re^2: CR+LF ("\n" ne "\r")
by tye (Cardinal) on Jun 19, 2003 at 22:44 UTC

    Items 1, 2, and 4 don't solve the stated problem. They result in only CR on the ends of lines (not in only LF on the ends of lines).

    Also, your not mentioning "\r" in item 1 makes me think that you may have been confused (like so many) by the '"\n" is logical newline' idea that I find horrid. See Re^4: Line Feeds (rumor control) for more on that.

                    - tye

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://267053]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (10)
As of 2014-04-17 10:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (444 votes), past polls