I have a script that calls on itself depending on certain parameters. The 1st instance of the script displays several input fields.. when submit is clicked, the same script is run again and output is displayed. The problem i'm having is that when i click refresh to bring up the first input
part of the script, it just keeps displaying the output part.
I'm using a local web server on a win98 machine. I have to restart the web server and close/open the browser to get the first part/input part of the script to display again.
Any Idea's? Here's the script. Thanx, Lisa.
$InputFile = "input.txt"; $TextFile = "story2.htm"; $CGIURL = "weblibs.pl"; print "Content-type: text/html\n\n"; read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs){ ($name, $value) = split(/=/, $pair); $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; if ($FORM{$name}) { $FORM{$name} = "$FORM{$name}, $value"; } else { $FORM{$name} = $value; push (@variables,$name); } } if ($FORM{'TextFile'}) { &SendFile; } if (-d $TextFile) { opendir(FILES,$TextFile); @tempfiles = readdir(FILES); closedir(FILES); foreach $file (@tempfiles) { if (-T "$TextFile/$file") { push (@files, $file); } } srand(); $files = @files; $file = @files[int(rand($files))]; $TextFile = $TextFile."/".$file; } open (FILE,"$TextFile"); @LINES = <FILE>; close (FILE); $text = join(' ',@LINES); $text =~ s/\n/ /g; $text =~ s/</\n</g; $text =~ s/>/>\n/g; @text = split('\n',$text); undef (@variables); foreach $line (@text) { if ($line =~ s/<!--(.*)-->/$1/) { push (@variables,$line); } } @sortedvariables = sort (@variables); open (FILE,"$InputFile"); @LINES = <FILE>; close (FILE); foreach $line (@LINES) { if ($line =~ /<!--InputWords-->/i) { print "<FORM METHOD=POST ACTION=\"$CGIURL\">\n"; print "<INPUT TYPE=HIDDEN NAME=TextFile "; print "VALUE=\"$TextFile\">\n"; print "<P><CENTER><TABLE>\n"; foreach $variable (@sortedvariables) { next if ($variable eq $lastvariable); print "<TR><TD ALIGN=RIGHT><P>$variable: </TD>"; print "<TD><INPUT TYPE=TEXT NAME=\"$variable\" SIZE=25>"; print "</TD></TR>\n"; $lastvariable = $variable; } print "</TABLE></P>\n"; print "<P><INPUT TYPE=SUBMIT VALUE=\"See the Results!\">\n"; print "</CENTER></P></FORM>\n"; } else { print $line; } } exit; sub SendFile { open (FILE,"$FORM{'TextFile'}"); @LINES = <FILE>; close (FILE); $text = join(' ',@LINES); $text =~ s/\n/ /g; foreach $variable (@variables) { if ($FORM{$variable} eq "") { print "incomplete!\n"; exit; } $text =~ s/<!--$variable-->/<STRONG>$FORM{$variable}<\/STRONG> +/g; } $text =~ s/A\/an <STRONG>(a|e|i|o|u)/An <STRONG>$1/g; $text =~ s/a\/an <STRONG>(a|e|i|o|u)/an <STRONG>$1/g; $text =~ s/A\/an/A/g; $text =~ s/a\/an/a/g; print $text; exit; }

In reply to Refreshing a perl script by wolverina

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.