×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

this is messing up the database

this is messing up the database

this is messing up the database

(OP)
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

RE: this is messing up the database

(OP)
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

RE: this is messing up the database

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

RE: this is messing up the database

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

RE: this is messing up the database

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close