MacResource
Perl Programming Question - Printable Version

+- MacResource (https://forums.macresource.com)
+-- Forum: My Category (https://forums.macresource.com/forumdisplay.php?fid=1)
+--- Forum: Tips and Deals (https://forums.macresource.com/forumdisplay.php?fid=3)
+--- Thread: Perl Programming Question (/showthread.php?tid=31216)



Perl Programming Question - The UnDoug - 04-09-2007

I have a web application that allows a user to submit information in "textarea" form fields. The information is written to a MySQL database, and then written out to a text file. The text file is transferred to another system and read into a different type of database.

If the user submitting the form has pressed the enter key in the textarea, or is pasting in from a Word document, there are sometimes html "
" tags in the data. I have been trying to get them out completely, because the text file that is transferred to the other system causes the program on that system to fail if it contains line breaks within a record.

I can get the "
" tags out by doing a perl replace regular expression:
$variable_name =~s/
//g;

but the text file still contains blank lines where it replaced the "
" tags. I'm also doing a replace for \n and \r (the newline characters)--I'm doing that replace before replacing for the "
" tags, if it matters.

Is there a Perl statment I can use to remove blank lines as I read through the variables one by one?


Any help is appreciated.


Doug


Re: Perl Programming Question - The UnDoug - 04-09-2007

I think I may have figured it out.

Any suggestions are still welcome, though.


Re: Perl Programming Question - Lux Interior - 04-09-2007

Here are some generic filters I used for form submissions. Strip out HTML & other non-text stuff:

$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s///g;
$value =~ s/<([^>]|\n)*>//g;