OK, here's the situation:

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>&nbsp;</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>&nbsp;</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>&nbsp;</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>&nbsp;</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>&nbsp;</td> POINT print " <td valign='top'><TEXTAREA NAME='alx' ROWS= +15 COLS=50>$alx</TEXTAREA><br>\n"; print " <INPUT TYPE=SUBMIT VALUE='Preview'>&nbsp;&n +bsp;&nbsp;<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 " &nbsp;&nbsp;&nbsp;<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


In reply to Extra blank lines in script output by emav

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.