Gossamer Forum
Home : Products : DBMan : Customization :

Replace carriage return characters

Quote Reply
Replace carriage return characters
Hi,
I'm have problem in removing the "carrige returns" before displaying. What I have is a number of textarea in my DB where user press the "Enter" or "Return" key and from what I can see when the request is submitted the record looks like this in the DB file
1|Test1````|Test2````|test3````|comments|
2|Test1````|Test2````|test3````|comments|
.
.
5|Test1````|Test2````|test3````|comments|

Q1. Are these ```` the carriage returns.?

Q2. If so why can't I search and change these ```` to . or a space. Here is the code I'm using to no avail.
open (DB, "<$db_file_name") or &cgierr("error in count. unable to open database: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB,1); }
@lines = <DB>;
close DB;
foreach $line (@lines) {
chomp ($line);
@data = &split_decode($line);
++$count{$data[8]};
++$total_count;
}

then I'm doing
foreach $line (@lines) {
chomp ($line);
@data = &split_decode($line);
if ($data[13] eq "Waiting" && $data[19] eq "Open") {
$data[1] =~ s/``/./g;
print qq|
.
.
|;
}
}

I can't seem to replace the ```` with . or a space.

Thanks in advance for any help or advise on what I'm doing wrong.
Quote Reply
Re: [cwilcox] Replace carriage return characters In reply to
Quote:
Q1. Are these ```` the carriage returns.?

Sorta. They're new line characters.

The reason you can't change them to a . is that the . is a special characer in regular expressions. Try

Code:

$data[1] =~ s/``/\./g;


Replacing them with spaces should be just as straigtforward:

Code:
$data[1] =~ s/``/ /g;



If you have ```` you'll end up with two spaces in a row. If you try to display that on a web page, though, you'll only see one space. html doesn't display multiple spaces. If you want to show two spaces on a web page, you'll need to use

Code:

$data[1] =~ s/``/&nbsp;/g;




JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.