in reply to Storing multi-line form data in a flat file?

It's difficult to know what exactly you mean with such limited information, but I think that you probably want something along these lines:
use CGI qw(:cgi); use strict; my $flatfile = "somefile.txt"; my $query = CGI->new(); my $text = $query->param("text_box"); open(FLATFILE, ">>somefile.txt") or die "Open failed, $!"; print FLATFILE "$text\n\n"; close(FLATFILE); print "Content-type: text/html\n\n"; print "Success!";
This code assumes that A. you want to append the data to a growing file with each submission, and B. you only want the data from a single form field called "text_box".

Update: Oh, and it also assumes that you want 2 line breaks between each entry in the text file.

Hot Pastrami

Replies are listed 'Best First'.
Re: Re: Storing multi-line form data in a flat file?
by SilverB1rd (Scribe) on Mar 15, 2001 at 02:15 UTC
    Yeah that is close but what if some one typed in "haha\n\nhaha...a hundred or so later..\n\n" This could really mess up my flat file. I want to encode this so I can store the data and retrieve it later.

    ------
    The Price of Freedom is Eternal Vigilance
      If the user types in a backslash than an "n", you'll be fine. If he/she puts in line breaks you simply wish to get rid of, use this:
      $text =~ tr/\n\r//;
      If you want to replace the line breaks with some other character, place the replacement character between the 2nd and 3rd slashes.

      Update: An easier way might be to borrow escape() from the CGI module, which escapes anything non-alphanumeric to it's alias (like "&" becomes "&"):
      $text = CGI::escape($text);
      When you want to translate it back to it's original form, use CGI::unescape();

      Or, if you're trying to make a home-grown database (which is not recommended), try using Berkeley DBM. It'll take care of all that stuff for you, be much faster, and much less bug-prone.

      Hot Pastrami