in reply to printing \n to a file

It sounds like you may be on Windows, opening the file in Notepad.

Change the line ending to "\r\n", and see if that helps.

Otherwise, tell us which OS you're using and how you're viewing these files, and we may be more helpful.

Replies are listed 'Best First'.
RE: Re: printing \n to a file
by davorg (Chancellor) on Oct 16, 2000 at 12:27 UTC

    Surely Perl should take care of those translations for you. You don't have to change the line end characters in a script when you move it from Unix to Windows (or vice versa) do you?

    Sound to me like you're writing the file on a Unix file system and then transfering it to Windows using a binary file transfer mechanism. This article may shed a little more light on the problem.

    Otherwise, as chromatic says, give us more details where and how you're reading and writng these files and we can probably be more help.

    --
    <http://www.dave.org.uk>

    "Perl make the fun jobs fun
    and the boring jobs bearable" - me

      Surely Perl should take care of those translations for you. You don't have to change the line end characters in a script when you move it from Unix to Windows (or vice versa) do you?

      Yes you do. (Note that perl itself understands unix line-end speak when reading in a script, but that's a different beast)

      Perl isn't going to try and automatically translate, because it doesn't know WHY you are writing what you are writing. It's very possible that you DON'T want the \r automatically inserted/deleted (For example, this would break all the Dos<->Unix one liner converters.)

      Update: As tye points out below, I missed the boat here.

        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")