Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Wont write to text file.

by ajt (Prior)
on Aug 01, 2002 at 10:54 UTC ( #186726=note: print w/replies, xml ) Need Help??

in reply to Wont write to text file.

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.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://186726]
and a moth chases the moon...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2016-12-07 11:58 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (125 votes). Check out past polls.