#!/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 () { if (/^\#.*/) { chomp; print hidden(-name=>"key$i", -value=>"$_"); $i++; next; } s/#.*//; # strip trailing comments next unless /\S/; # skip blank lines my ($key, $val) = split /\t+/; $val = $key unless $val; print " \n"; print " \n"; $i++; } close PATS; # use old style for now - clean up later... print " \n"; print " \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; }