Hopefully this is within your wisdom. I have a CGI script that when accessed from a web browser, loads file data into form input fields. After the user modifies the fields and presses the submit button, the new values are written back into the file. SImple. But I want more. I want the screen to refresh with the new values populated in the form input fields. My approach was to try redirecting to the same page. Instead, my code (below) seems to bring up the cached values and write those to the file the second submit. Is there a way I can get the whole script to start over, and read the values in from the newly written file? Thanks.
#!/usr/local/bin/perl use CGI qw/:standard/; my $new_cgi = new CGI; my $i=0; $| = 1; # no more buffering my $full_url = $new_cgi->url(); print header, start_html('Pattern editor'), h1('Pattern Edit Center'), start_form; open PATS, "pats.txt" or die "cannot open pats.txt\n"; while (<PATS>) { if (/^\#.*/) { chomp; print hidden(-name=>"key$i", -value=>" +$_"); $i++; next; } s/#.*//; # strip trailing comme +nts next unless /\S/; # skip blank lines my ($key, $val) = split /\t+/; $val = $key unless $val; print "<TR><TD><input type=text name=key$i siz +e=13 value=$key> </TR>\n"; print " <TD><input type=text name=val$i size=2 +4 value='$val'> </TD></TR>\n"; $i++; } close PATS; # use old style for now - clean up later... print "<TR><TD><input type=text name=key$i size=13 > < +/TR>\n"; print " <TD><input type=text name=val$i size=24 > </T +D></TR>\n"; print submit, end_form, hr; if (param()) { open PATS,">pats.txt" or die "Cannot open pats.txt\n"; my $j = 0; while ($j <= $i) { print PATS param("key$j"), "\t", param("val$j") . "\n"; $j++; } close PATS; # Now that I've written the file, I should be able # to refresh and read the values back in. But How? print redirect($full_url); # for debugging purposes, print the form values to the bottom of page $j=0; while ($j <= $i) { print em(param("key$j")), " ", em(param("val$j")),br; $j++; } hr; }

In reply to CGI refresh w/a twist by Anonymous Monk

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.