CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Regular Expressions:
double replacement



Feb 23, 2003, 3:21 AM

Post #1 of 5 (12157 views)
double replacement Can't Post

I have tried several solutions, but none seemed to solve my problem. I have several text areas that each require multiple carriage returns. But I am trying to replace those carriage returns with a 'symbol' and then of course have the script (and other scripts that use the information) turn the 'symbol' into line break. The info is part of a large pipe delimited database. I can't have the returns in the database obviously, but I DO want them to appear in any HTML pages which are based on all of the info in the database. Some of the textareas may include double returns such as a paragraph.

All and any help are greatly appreciated! Thanks!


Feb 23, 2003, 4:22 AM

Post #2 of 5 (12151 views)
Re: [etheracide] double replacement [In reply to] Can't Post

Something like


is not enough, then?


Feb 23, 2003, 10:07 PM

Post #3 of 5 (12149 views)
Re: [thodi] double replacement [In reply to] Can't Post

It appears to not work...atleast not in the manner I was hoping.

But thank you for the attempt =0)

Any other possible solutions?

Thaumaturge / Moderator

Feb 24, 2003, 1:19 AM

Post #4 of 5 (12148 views)
Re: [etheracide] double replacement [In reply to] Can't Post

Perhaps you could explain in what way the previous solution isn't doing what you want.

And if you could post your code, it would be much easier to help you.

Dave Cross, Perl Hacker, Trainer and Writer
Get more help at Perl Monks


Feb 25, 2003, 8:50 PM

Post #5 of 5 (12138 views)
Re: [davorg] double replacement [In reply to] Can't Post

I will write out an example of my code. Most of it is not needed for this problem so I will write the most pertinent of info to

this problem. i will also explain what the above code did for me.

This 'program' is multiple scripts. It is supposed to allow a user to create, preview, and then save their resume.

Once they finish entering their info, they hit the submit button which takes them to the preview. The preview

script captures the information from the following page and if a field had a value, it prints the text for it and then

it's value. Simple enough.

The second script then has a submit button which the user will click if they are satisfied with how the resume looks.

The save script will save the html to an html file named $username.html and also takes the information and saves it

to a database. The database is named $username.dat and features the password, E-mail address and all of the information

that goes into the resume. This of course is used for password verification upon login, sending of mails to their E-mail address,

and when the user edits their resume, the editing script pulls the info from the database to 'pre-fill' the form. Well the info isn't

being saved properly in the database and therefore can't be put into the resume editor properly.

The resume creating/editing script has textareas such as a box for references. The user should be able to enter multiple

references into this one box. They should be able to 'return' for each new line such as name (line one), street address, town state

and zip (line three) how long they've known them (line four) and contact number (line five). And then double 'return' to start the

next reference. I am not concerned with the number of lines exactly...I just want the user to be able to use carriage returns.

Now, the preview script should use this info in two ways. It should take out the newlines and replace them with <br />

(to be compliant with HTML4) for the part where it saves the HTML to the html file. But, the script should strip out the

newlines and and place any 'symbol' (except for pipe since I use that for the rest of my database) where the carriage returns

are. This is done so that in the creating/editing code, I can make the script then replace the symbols with newlines so that

the references will appear correctly in the textarea.

Here's my attempt to show the important information of each script.

The resume creating/editing script with textarea and taking symbol (I decided to go with a number sign

JUST FOR AN EXAMPLE here) out and replacing it with newlines to make the formatting correct in the textarea. The value

for references is pulled from the $username.dat but I am leaving that out of the code.


$references =~ s/#/\n/g;

print "<tr><td><span class=text>References:</span></td><td>

<textarea name=references cols=25 class=input>$references</textarea></td></tr>";


Now the preview script takes the references and other information and creates an HTML page so that the user can see

how their resume will look as it stands. You will notice the use of hidden fields to send the values to the script which will

save the info. The value of references being passed to the preview script will have newlines in it. I want to turn those

newlines into HTML line breaks (<br />) to properly format it for the HTML document that will be created.


Because of the formatting done to the the value of $references done in the previous step, the value of $references

still holds those

<br />'s. Those should be kept in the value for saving the HTML because they are needed to format them in the html

page. But

there's a save_customer subroutine and there has to be formatting there that will not mess up the database, but

also allow for

the editing script to know that a newline goes there in the textarea.

 $references = $christophersnyder->param('references');&save_customer;if ($references eq "") { 

print "";


print "<tr><td><span class=text>References:</span></td><td><span class=body>$references</span></td></tr>";


sub save_customer {

$references =~ s/<br \/>/#/g;

open(CUST, ">data/$customer.dat");

print CUST "$password|$email|$references";




Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives