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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Forced data formatting..handling \n\r

 



S_Shrum
User

Apr 3, 2001, 1:26 PM

Post #1 of 3 (291 views)
Forced data formatting..handling \n\r Can't Post

I am trying to prescreen what the users input and make sure that certian character(s) are not input and are replaced with a more db friendly mixture of characters. Example, I am tring to do:

Foreach ( $input) { $_ =~ tr/\n\r/ /d; }

...where I am replacing <new line><carriage return> with 2 SPACE characters. I even thought that I may have set it up wrong and tried:

Foreach ( $input) { $_ =~ tr/\r\n/ /d; }

...switching the \n\r around. This is not working for me.

The data is coming from a html form if that makes any difference.

Any ideas????

Sean Shrum
sean@shrum.net
www.shrum.net


sleuth
Enthusiast

Apr 3, 2001, 11:27 PM

Post #2 of 3 (285 views)
Re: Forced data formatting..handling \n\r [In reply to] Can't Post

Hmmm, the way you're going about that looks weird.

I do this constantly also, except I usually don't use text area's too often so i never have to loop through a whole hash with the information passed to my program. So what I do is just take the text area field names and translate the carriage returns & new lines.


Code
$in{'textform'}=~s!\n!< br >!g; 
$in{'textform'}=~s!\r!!g;

I use breaks, this way when I show the user their information again I don't have to bother converting anymore. But when I want to put the information back into a text field, I can easily convert the breaks back into new lines. Another thing, when you make a carriage return it goes into the text area field as \n\r or as \r\n, I can't remember for sure, but anyway, you only need to pick one to convert. Converting both using something like this


Code
$in{'textarea'}=~s![\r|\n]!< br >!g;

would double the breaks for each return.

Maybe this helped if it didn't oh well,

Tony

P.S As for converting characters in all passed fields, I always do this


Code
foreach $key (keys %in){ 
$in{$key}=s!bad!good!g;
}



S_Shrum
User

Apr 4, 2001, 9:06 AM

Post #3 of 3 (282 views)
Re: Forced data formatting..handling \n\r [In reply to] Can't Post

That did the trick. Thanks.

Sean Shrum
sean@shrum.net
www.shrum.net

 
 


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

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