
serazoo
New User
Apr 19, 2009, 4:57 PM
Post #1 of 3
(1177 views)
|
|
PRESERVING Line break in perl
|
Can't Post
|
|
Hello all... please help, I've tried so many combination of scripts...I'm going bananas :) I've would like my textarea to preserve all line breaks when saved into the database (.txt) file please tell what could be the magic line to insert and where ? cheers Sandra :) here's my script: ------------------------------------------- sub new_items{ $form{'function'} eq "save_new_items" and &save_new_items; # Section Heading ########################### print qq~ <P> <table border="0" width=98%" cellspacing="0" cellpadding="0"> <tr> <td bgcolor="800000"><font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="ffffff"><b>Add New Items</b></font></td> </tr> <tr> <td bgcolor="000000"><img src="space.gif" width="1" height="2" vspace="0" hspace="0"></td> </tr> <tr> <td> <font size="2" face="Verdana, Arial, Helvetica, sans-serif"> <ul> <br> $save_message ~; $counter = 1; foreach (@table_fields) { $size = ""; $fieldsize{$counter} and $size = qq~size="$fieldsize{$counter}"~; !$form{$counter} and $form{'function'} ne "preview" and $form{$counter} = $default_input{$counter}; $datatype{$counter} eq "Text" and $input = qq~<input type=text name="$counter" value="$form{$counter}" $size>~; $datatype{$counter} eq "Textarea" and $input = qq~<textarea name="$counter" cols="46" rows="20" $fieldsize{$counter}>$form{$counter}</textarea>~; $datatype{$counter} eq "Option" and do{ @options = split (/\n/, $optionfields{$counter}); $input = qq~<select name="$counter">\n~; foreach $option(@options) { $selected = ""; $form{$counter} eq $option and $selected = "selected"; $input .= qq~<option $selected>$option</option>\n~; }#end foreach option $input .= qq~</select>~; };#end option do $datatype{$counter} eq "Checkbox" and do{ $checked = ""; $form{$counter} and $checked = "checked"; $input = qq~<input type=checkbox name="$counter" value="1"> $optionfields{$counter}~; };#end checkbox do print qq~ <font size="2" face="Verdana, Arial, Helvetica, sans-serif" color=""> <b>$_:</b></font><br> $input<P> ~; $counter++; } print qq~ </ul> </td> </tr> </table> <p> <font size="2" face="Verdana, Arial, Helvetica, sans-serif" color=""> <center> <b> <input type=hidden name="menu" value="new_items"> <input type=radio name="function" value="save_new_items" checked> Save Directly <input type=radio name="function" value="preview"> Preview<P> </b> <input type=submit value="Send New Entry"> <P> </center> ~; } ########################################### sub save_new_items { $error_message = ""; $new_line = ""; $counter = 1; &load_db; foreach (@table_fields) { $requiredfield{$counter} and !$form{$counter} and $error_message .= qq~<b>$_</b> is a required field, and nothing has been entered.<br>~; $uniquefield{$counter} and !$form{$counter} and $error_message .= qq~<b>$_</b> is a unique, required field, and nothing has been entered.<br>~; # Check Required Status ####################################### $uniquefield{$counter} and $form{$counter} and do{ foreach $keys (keys %data_hash) {$data_hash{$keys}{$_} eq $form{$counter} and $error_message .= qq~<b>$_</b> is required to be a unique field, and has been found in the database at line $keys.<br>~;} };#end required field do # Remove New Lines ###################################### $form{$counter} =~ (s/\r\n/ /g); # Create New Line By Adding Next Field ###################################### $new_line .= qq~$form{$counter}|~; $counter++; } # Save if No Errors ###################################### !$error_message and do{ open (FILE, ">>$data_file"); print FILE qq~$new_line\n~; close (FILE); chmod(0666,"$data_file"); %form = (); $save_message = qq~<b>New Record Has been Saved</b><P>~; };# end save to file # Report Errors if Present, Return ###################################### $error_message and do{ $save_message = qq~New Record Has <b>Not</b> been Saved. Please correct the following:<P>$error_message<P>~; };# end save to file }#end save new items 1; ------------------------------------------
|