PDA

View Full Version : Default Whitespace?


netroact
07-04-2006, 01:54 AM
I have a script that reads from a text file and populates a textarea for review. After any newlines or returns between paragraphs there is a whitespace displayed in the textarea. There isn't a leading whitespace in the text file. I can read from the same text file to an html file with no textarea, and it does not add a leading whitespace. Is there something about a textarea that causes it to add a leading whitespace?

Here is a relevant snippet from the code:

open (EDITDATA,"/home/user/public_html/cgi-bin/content.txt");
my @content = <EDITDATA>;
close (EDITDATA);

my $content = "@content";
$content =~ s/(<br>)?//g;

print <<EOF;
<table width="750" height="650" align="center" bgcolor="ffffff" cellspacing="0" cellpadding="0">
<tr>
<td width="750" height="650" align="center" bgcolor="f0f0f0" cellspacing="0" cellpadding="0">
<form method="POST" action="content.pl" ENCTYPE="multipart/form-data">
<br>
Content:<br>
<textarea name="content" rows="25" cols="60">$content</textarea>
<br>
<br>
<input type="submit" name="submit" value="Submit">
</form>
</td>
</tr>
</table>
EOF


Thanks!

FishMonger
07-04-2006, 02:20 AM
I'm not sure how much whitespace you're refering to, but part of the problem is that you're using quotes around @content when assigning $content. That statement will join the array elements with the list separator, which by default is a space.

Read in your file like this:

my $content = join '', <EDITDATA>;

netroact
07-04-2006, 02:41 AM
It works! Thanks Fishmonger! Now I need to learn what that code means.

FishMonger
07-04-2006, 03:00 AM
I haven't tested it, so this may need a little tweeking, but you should be able to readin the file into the scalar and do the substitution at the same time.

my $content = join '', <EDITDATA> =~ s/(<br>)?//g;

netroact
07-04-2006, 04:11 AM
Can't modify <HANDLE> in substitution (s///) at edit_news_content1.pl line 65, near "s/(<br>)?//g;"