Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked


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.


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!

Replies are listed 'Best First'.
Re^2: CR+LF ("\n" ne "\r")
by tye (Sage) 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://267053]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2018-06-21 04:47 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (117 votes). Check out past polls.