How do you use a perl script to empty a text file and then replace it with data from a web form? Here I first get the data from the file, then I use the web form to update it. The delete old data part works, but the new data doesn't get added to the file. $FORM{'content2'} doesn't get registered when editing it.
#!/usr/bin/perl ################### use CGI ':standard'; use CGI qw(:standard); # then only CGI.pm defines a head() $page = param('page'); #/cgi-bin/edit.cgi?page=edit print header(); if ($page eq 'edit') { #This part creates a form with the content from the edit.shtml file. use LWP::Simple; $content = get ('http://www.domain.com/edit.shtml'); print <<EOM; <title>Test</title> <meta http-equiv="Cache-Control" content="no-cache, no-store, must-rev +alidate"> <META HTTP-EQUIV="Expires" CONTENT="-1"> <HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE"> <FORM METHOD=POST ACTION="http://www.domain.com/cgi-bin/edit.cgi" name +="myForm"> <textarea title="Content (optional)" name="content2" cols="100" rows=" +50">$content</textarea> <BR><input type="submit" value="SUBMIT"/></form> EOM } else { $database = "/home/site139/public_html/edit.shtml"; # Get the input read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); # Split the name-value pairs @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; } { #Here I delete the edit.shtml page. open my $empty_the_file, "> /home/site139/public_html/edit.shtml" or d +ie "Can not write file: edit.shtml $!" ; close $empty_the_file; #Here I try to put in the data from the form but $FORM{'content2'} doe +sn't get registered. open (DATABASE,">>$database"); print DATABASE "$FORM{'content2'}\n"; close(DATABASE); } print <<EOM; <HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE"> Page edited. <P> $FORM{'content2'} EOM exit; }

In reply to Use a perl script to empty a file and then replace it with data from a web form by Jesse Smith

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.