einerwitzen has asked for the wisdom of the Perl Monks concerning the following question:

when I currently print text from a textarea to a file it loses its line breaks. I think that this can be saved by printing in binary instead of ASCII. Is there a way to do that?

Replies are listed 'Best First'.
Re: printing text to a file in binary
by brian_d_foy (Abbot) on Jun 23, 2005 at 22:10 UTC

    Are you sure you had the line breaks in the first place? What you see in the textarea is not necessarily what you are going to get in the CGI program. Google can lead you to many discussions of this.

    Good luck :)

    --
    brian d foy <brian@stonehenge.com>
      it is kind of a content manager, it is a single script that receives text which is actually HTML formatted (tabs and lines and such) and takes the HTML that is sent to it and saves it to a .html file. The created page displays fine, but when downloaded or the source is viewed all the html is just one huge block of text.....
Re: printing text to a file in binary
by PerlingTheUK (Hermit) on Jun 23, 2005 at 22:01 UTC
    Look for binmode and pack in the perldoc. That way you can save the text as binary. However I am not sure if it also causes the line breaks to be restored.

    Cheers,
    PerlingTheUK
Re: printing text to a file in binary
by GrandFather (Saint) on Jun 23, 2005 at 22:07 UTC
    Show us a sample of the code that is causing you grief. For preference with a sample of the before and after text.

    Perl is Huffman encoded by design.
Re: printing text to a file in binary
by TedPride (Priest) on Jun 24, 2005 at 04:57 UTC
    The text from the textarea probably does its line breaks with just \n, while your text editor (Notepad?) requires both \r\n. You should try removing all instances of \r and then replacing \n with \r\n. This will hopefully fix your problem.
Re: printing text to a file in binary
by orkysoft (Friar) on Jun 25, 2005 at 04:43 UTC
    Perhaps you have the text in a list of lines without linebreaks, and then print them without inserting linebreaks? There are so many things that can go wrong, and your description is so vague, that all of the wildly differing suggestions posted here might be applicable.

    --
    Morbo: "Windmills do not work that way!"

Re: printing text to a file in binary
by anonymized user 468275 (Curate) on Jun 24, 2005 at 13:09 UTC
    text areas use \n<BR> instead of \n as line breaks.

    -S