Good to see you using CGI, but I think you'll find adding warnings and strict is always useful too. You can start warning by adding -w to the shebang line, or on more modern Perls by loading the warning module. Turn strict on by using it too. e.g.

#!/usr/bin/perl -w use strict; use warnings;

Looing at your code, and I assume it's a cut'n'paste, rather than a re-type, I'd say that you could clean up your open statment to something like:

open FILE, ">>", $filepath or die "Unable to write to file\n$!";

Secondly you are loading all of CGI, but then doing your own HTML, which is a bit of a waste. Either load only the bits of CGI you want (e.g. use CGI qw(:cgi); or take advantage of it's HTML printing. For example:

print header; print start_html(-title => 'Web Pages for local data.'); ... print p("Data Submitted.", br, b($newtext)); print end_html;

Depending upon which version of CGI you are running you should be able to start the script from the command line, and pass dummy variables to it, which can help with debugging.

Another debugging tip from the docs is the Dump option, which will make CGI spit out in crude HTML all it's input parameters, so you can see if there is something funny going on, for example the param has a differnt name in the HTML form. See the CGI docs for more details.

UPDATE: If you are going to use the OO interface for CGI, it's better to:

my $q = CGI->new;

rather than:

my $q = new CGI;

See davorg's comments in Re: (elbie): What does this warning mean? for an explanation.


--
ajt

In reply to Re: Wont write to text file. by ajt
in thread Wont write to text file. 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.