Re: script adding spaces into a file for no reason...
by httptech (Chaplain) on May 20, 2000 at 00:40 UTC
|
When you print an array like
print <<END;
<textarea>@text</textarea>
END
it will print all lines of the array joined by
a space. Instead, you can use:
<textarea>@{[join("",@text)]}</textarea> | [reply] [d/l] [select] |
|
|
<textarea>@{join("",@text)}</textarea>
the proposed solution still returns an array; It needs to be taken out of array context.
Instead of print <<END ,
try:
print "<textarea>" . join ( "", @text ) ."</textarea>\n" ;
This is presuming, of course, that the "\n" is already on the end of each element of @text. if not, you might want to join them with "\n".
Also, be aware that some browsers may take it upon themselves to make each line ending a "\n\r" - especially if you cut and paste into the textarea. I make it a habit to:
$input =~ s/\r//g ;
On all submitted form values to clean it up.
| [reply] |
|
|
| [reply] [d/l] |
|
|
|
|
I tried reading the source .. and used that code-- it runs w/o errors, but unfortunately didn't fix..
I used: print "<textarea>" . join ( "", @text ) ."</textarea>\n" ;
hmm.. this is really strange. any other ideas?>
Joe
| [reply] [d/l] |
|
|
|
|
ack! (look at the html source to decipher previous reply)
| [reply] |
|
|
| [reply] |
|
|
oh.. wait.. ;-)
Now its inserting like 3 ADDITIONAL paragraph marks (or hard returns) -- whatever you want to call them.. The only way I could tell was by pasting the code into MS Word and seeing them when I enabled "show P marks".....
any ideas for this problem?
Joe
| [reply] |
|
|
I don't see any extra newlines... Where are they appearing?
| [reply] |
|
|
RE: script adding spaces into a file for no reason...
by Anonymous Monk on May 20, 2000 at 02:41 UTC
|
Submitting text from a text area adds a \n and a \r to the end of everyline...
Strip the incoming text of \r and you'll be fine.... | [reply] |
Re: script adding spaces into a file for no reason...
by arcterex (Acolyte) on May 20, 2000 at 01:55 UTC
|
Could you not do something like:
Convert \n to a BR tag when you save, then when you display the file convert the BR's to newlines? ie:
<CODE>
sub save {
$text = $cgi->param("text");
$newtext = s/\n/ /g;
# save $newtext to somewhere...
}
# and when you retrieve
sub load {
$text = ... # get variable from file
$newtext = s/ /\n/g;
print "<textarea>$newtext | [reply] |
Re: script adding spaces into a file for no reason...
by turnstep (Parson) on May 20, 2000 at 00:37 UTC
|
| [reply] |