emav has asked for the wisdom of the Perl Monks concerning the following question:
I created a perl script to automatically create some files on my web site. Like the good and meticulous webmaster that I am, I thought that I had better preview my files before they are added to my website (it's very much like the node-preview blessing we've got here in the monastery). So, I made a script (try.pl) that calls itself to do the preview or another (check.pl) to actually add the new file to my web site.
It works fine apart from an annoying glitch. Extra blank lines appear in the text area, where the html code is listed for further editing. Actually, all my carriage returns are duplicated. If I try to preview the document again, I get more blank lines and you can imaging what kind of an html-code I get if I try to preview the document a few more times.
I've been wondering whether this is due to a problem in my perl script or something else. Maybe you, brothers, could help. Here's the code:
#!/usr/bin/perl -- print "Content-Type: text/html\n\n"; $center = "center.htm"; # html template # taken from formmail %Config = ('dir','','fil','','ttl','','alx',''); read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { local($name, $value) = split(/=/, $pair); $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $name =~ tr/\0//d; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/\0//d; $value =~ s/\n//eg; if (defined($Config{$name})) { $Config{$name} = $value; } } $dir = $Config{dir}; $fil = $Config{fil}; $ttl = $Config{ttl}; $alx = $Config{alx}; $fl = join '', "../ujo/", $dir, "/", $fil, ".txt"; open CENTER, $center or die "Cannot open $center for read :$!"; while (<CENTER>) { if (/text begin/) {$ate = 1;} if (/text end/) {$ate = 0;} if (/\<\/body\>/) {&printform;} if ($ate) {&printate;} else {print;} } sub printate{ print "<!--text begin-->\n"; print $alx; } sub printform{ print "<p> </p><center>\n"; print <<POINT; <table border="0" cellpadding="0" cellspacing="0" styl +e="border-collapse: collapse" bordercolor="#111111" id="AutoNumber1"> <FORM ACTION="../cgi-bin/try.pl" METHOD=POST> <tr> <td valign="top">Directory:</td> <td> </td> POINT print " <td valign='top'><INPUT NAME='dir' SIZE=50 +value='$dir'></td>\n"; print <<POINT; </tr> <tr> <td valign="top">File:</td> <td> </td> POINT print " <td valign='top'><INPUT NAME='fil' SIZE=50 +value='$fil'><p></td>\n"; print <<POINT; </tr> <tr> <td valign="top">Title:</td> <td> </td> POINT print " <td valign='top'><INPUT NAME='ttl' SIZE=50 +value='$ttl'><p></td>\n"; print <<POINT; </tr> <tr> <td valign="top">Text:</td> <td> </td> POINT print " <td valign='top'><TEXTAREA NAME='alx' ROWS= +15 COLS=50>$alx</TEXTAREA><br>\n"; print " <INPUT TYPE=SUBMIT VALUE='Preview'> &n +bsp; <INPUT TYPE=RESET VALUE='Reset'\n"; print " <input type=hidden name='sort' value='order +:=env_dir,fil,ttl,alx'></form>\n"; print " <FORM ACTION='../cgi-bin/check.pl' METHOD=POS +T>\n"; print " <INPUT TYPE=HIDDEN NAME='dir' VALUE='$dir'>\n +"; print " <INPUT TYPE=HIDDEN NAME='fil' VALUE='$fil'>\n +"; print " <INPUT TYPE=HIDDEN NAME='ttl' VALUE='$ttl'>\n +"; print " <INPUT TYPE=HIDDEN NAME='alx' VALUE='$alx'>\n +"; print " <INPUT TYPE=SUBMIT VALUE= +'Submit'>"; print " <input type=hidden name='sort' value='order +:=env_dir,fil,ttl,alx'>"; print "</td></tr></table></center>\n" }
Janitored by Arunbear - added readmore tags, as per Monastery guidelines
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Extra blank lines in script output
by JediWizard (Deacon) on Nov 08, 2004 at 15:35 UTC | |
|
Re: Extra blank lines in script output
by Mutant (Priest) on Nov 08, 2004 at 15:42 UTC | |
|
Re: Extra blank lines in script output
by talexb (Chancellor) on Nov 08, 2004 at 15:36 UTC | |
by emav (Pilgrim) on Nov 08, 2004 at 15:40 UTC | |
|
Re: Extra blank lines in script output
by steves (Curate) on Nov 08, 2004 at 17:56 UTC | |
|
Re: Extra blank lines in script output
by TedPride (Priest) on Nov 09, 2004 at 09:21 UTC |