Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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.


--
ajt


Comment on Re: Wont write to text file.
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://186726]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2014-09-20 07:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (155 votes), past polls