in reply to RE: RE: Re: printing \n to a file
in thread printing \n to a file

No, you don't. Unless you do binmode(FILEHANDLE), every "\n" you write to FILEHANDLE will be turned (by the C run-time library) into "\r\n" before it reaches the file. If you want to write a file that contains "\n" without the "\r", then have to use bindmode.

        - tye (but my friends call me "Tye")

Replies are listed 'Best First'.
RE: (tye)Re: printing \n to a file
by Fastolfe (Vicar) on Oct 17, 2000 at 01:03 UTC
    To avoid this confusion entirely, never use \n unless you are referring to the ASCII newline sequence, whatever that may be on your specific OS. If you truly want a binary ^M or ^J, consider using the \cM or \cJ codes.

      This makes sense to me as a self-documenting code practice (documenting what intent the programmer had when sending that newline to a file). However, I'd like to note that it won't fix the problem since, just like "\n" is silently turned into "\r\n" under Windows, "\cJ" will silently be turned into "\cM\cJ", since these are identical strings under Win32 (and most Perl platforms). In MacOS, "\n" is "\cM" and "\r" is "\cJ".

              - tye (but my friends call me "Tye")