Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

this is messing up the database

Status
Not open for further replies.

safra

Technical User
Jan 24, 2001
319
NL
Hi Guys,

I'm really not good with Perl but I managed to set up a little database system.

It works fine but one of the textfields in the form is a multiline field.

When saved to the database it is messing up the complete database.

I guess I first have to detect the newline command and then replace it for another character and save it.

When calling the info back from the database the character has to be replaced again into the newline command.

I know how to replace a normal character but how do I detect a neline command and replace it for another character?

I hope somebody can help me with this.

Regards,

ron
 
It is just a flattext database if that is how you call it.

it writes the variables to a txt file with ":" between them:


open (FILE, ">> $file") or &error("Could not open data file at line ", __LINE__);
flock FILE, 2 or &error("Could not lock data file at line ", __LINE__);
print FILE qq~$name:$email:$message\n~;
close FILE;
flock FILE, 8;

if $message has newline commands the txt file interprets this as a newline command and starts writing on the next line!

ron
 
then take the newlines out and replace them with some character so that when you want to print it back, you can put the newlines back in. adam@aauser.com
 
Safra,

If you have a string with embedded new-lines in you'll need to tell Perl about it with the /s modifier in the substitute command.

s/\n/;/sg;

The s tells Perl to look at the whole string, and not just up to the first new-line (\n) and the g says to replace all of the \n's and not just the first one.
Mike
michael.j.lacey@ntlworld.com
 
Great guys, thanks for that code Mike!

I feel stupid that I didn't came up with trying \n for that new line trace but I would never have thought of the last part.

I tried some things and actually for me this is very weird:

first I used:

s/\n/||/sg;

and

s/||/\n/sg;

to put the everything back as it was

This didn't work, the textfield looked like:

first line
||second line
||third line
||

What I tried next was:

s/\n//sg;

And nothing to put everything back.

This worked which seems very weird to me. Any idea if I should expect problems with this?

regards,

Ron

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top