Home: General Discussions: General Questions:
Line Breaks/Returns



ssmythe
New User

Oct 31, 2011, 9:40 AM


Views: 10657
Line Breaks/Returns

I'm have a problem with preserving line breaks. When the user fills in their company description on the form line breaks appear but when the data comes from the database the line breaks disappear! Can anyone help?

print $thebest->{cgi}->header;
my @company;
my $ctitle = "Company Description";
my $keywords = "Company Keywords";
my $cdescription = "Company Description";
my $companies = $thebest->database("getCompany", { "company_id" => $cid, geolocation => $geolocation });
use Data::Dumper;
foreach (@$companies) {
my $item = $_;
if($item) {
$item->{hash} = $thebest->auth("md5string", { "string" => "$item->{id}" });
if($item->{reviews_total} == 0) {
$item->{stars} = 0;
} else {
$item->{stars} = int($item->{reviews_total} / ($item->{reviews} - 1));
}
$ctitle = $item->{name}.": ".$item->{keywords};
$keywords = $item->{keywords};
my (@desc) = split(//, $item->{description});
my $adesc;
my $rowc = 0;
my $count = 0;
my $total = @desc;
while($count < $total) {
if($rowc == 60) {
$adesc .= @desc[$count];
$rowc = 0;
} else {
$adesc .= @desc[$count];
}
$rowc++;
$count++;
}
$item->{description} = $adesc;
$cdescription = $item->{sdescription} ;
push(@company, $item);

}


BillKSmith
Veteran

Nov 2, 2011, 7:05 AM


Views: 10400
Re: [ssmythe] Line Breaks/Returns

The safest "solution" is to chomp newlines from all inputs.
Add them to print statements when needed.
Good Luck,
Bill