
BigRich
Novice
Apr 26, 2001, 4:25 AM
Post #5 of 6
(2799 views)
|
First, make sure that your textarea tag has the "wrap" attribute set to "virtual" not "physical". (<textarea name="mytextarea" rows =5 cols=40 wrap="virtual">) Then remove any user entered "returns" and replace them with a space before printing it to the db. $textarea_in = $q->param('mytextarea'); $textare_in =~ s/(\r*\n)+/ /g; Now you should be able to print the input to the db without the returns. You'll lose the formatting if you plan to print it back out, if you want to retain the formatting for HTML output you could replace with break tags. $textare_in =~ s/(\r*\n)/<break tag here>/g; (Couldn't use an actual 'br' tag above because it was taken literally by this BBS script, tried <br> also) Perl doesn't care how the data looks in the database. If you are worried about retrieving the info, use a different record separator (other than 'newline') to seperate the records in the db. For example, if you want to store multiple records in a single flat file db and there were multiple entries within each record that could contain newlines, just specify a new record seperator and seperate the entries with something unique (and check that the user did not try to enter either of them). You could seperate records with, say, ~_~ (tilde, underscore, tilde) and the elements within the record with || (double pipe). A db could then look like. This is a record||This is an element||This is also|| So is this~_~ This is another record||element ||another element~_~ Then, read it into your script. my @data; { #contain the localization of $/ local $/ = '~_~'; #tell the script what record seperator we are using while (<DATA>) { chomp; #removes ~_~ push @data, $_; } } #end container Now @data is made up of the individual records which can be split into the individual elements on the double pipe delimiter. BigRich
|