Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

In my script, I am trying to take the user's input, use CGI.pm to sort out the data, then write that data to a file, with other data. Here is my script.
#!usr/bin/perl #Start the CGI! use CGI; #Declare a new page for the information my $Page = new CGI; #Put the data from the form into variables my $Name = $Page->param(Name); my $E_mail = $Page->param(E-mail); my $Comment = $Page->param(Comment); #A little bit of environment variables my $Browser = $ENV{"HTTP_USER_AGENT"}; #Open the file where the information will go. open(GUEST, '>>../GuestBook/GuestBook.txt') or die "The file could not + be opened."; #Open up the file for the counter to... "count" the people open(COUNT, '../Counter/counter.txt') or die "The File could not be op +ened."; #Save the contents to a variable $Number = <COUNT>; print COUNT $Number++; #Close it up close(COUNT); #Print all of the information, with the proper #HTML, to the file. print GUEST <<GuestStuff; <table border="0" cellspacing="1" cellpadding="0"> <tr width="200"> <td> <p style="size: 30px;">Otaku \#$Number.</p> </td> </tr> <tr> <td class="Cell"> <p style="color: white;">Name: $Name</p> </td> </tr> <tr> <td class="Cell"> <p style="color: white;">E-mail: $E_mail</p> </td> </tr> <tr> <td class="Cell"> <p style="color: white;">Comment: $Comment</p> </td> </tr> <tr> <td clas="Cell"> <p style="color: white;">Your Browser type: $Browser</p> </td> </tr> </table> GuestStuff #Print the HTML MIME header from CGI. print $Page->header; #Print to the screen print <<HYPERSTUFF; <html> <head> <title> Thank you! </title> <META HTTP-EQUIV="Refresh" CONTENT="10; URL=http://storm.prohosting.c +om/ertain"> <LINK REL="stylesheet" HREF="Style.css" TYPE="text/css"> </head> <body> <p>Thank you for your input! It will be on the GuestBook page, if y +ou want to see it. You will now be redirected to the main page.</p> <p>If it doesn't work in 10 seconds, here's the <a href="http://storm.prohosting.com/ertain">link</a>. </p> </body> </html> HYPERSTUFF #close the GuestBook file close(GUEST);
As you can see, the information is taken from the module, placed into variables, then is placed amongst the HTML, and written to a file. But I can't seem to get it to work.

Replies are listed 'Best First'.
Re: Writing to a file
by Asim (Hermit) on Nov 21, 2001 at 00:43 UTC

    If you're problem is that you can't see the error message that Perl is putting out, put use CGI::Carp qw(fatalsToBrowser); under use CGI; in your code, and see if that doesn't help.

    Your main problem might be with your Counter stuff; you're trying to read & write to it without telling Perl to open for both read and write. The very basic code for doing this would be something like open(COUNT, "+<../Counter/counter.txt") or die "The File could not be opened."; but you should read the docs and try it out. I suggest you start with the documentation on the open command for the details on how to make it happen, but be warned that "There be Dragons here..."

    ----Asim, known to some as Woodrow.

Re: Writing to a file
by dash2 (Hermit) on Nov 21, 2001 at 00:04 UTC
    My friend,

    Do you seriously expect anyone to answer you when you post 100 lines of code with the comment "I can't seem to get it to work"?

    Here's a useful piece of advice: when asking for help, explain what the problem is. What doesn't work? What error messages?

    Here's another, which you don't deserve: Perl has a debugging option which you can use as follows:

    perl -d scriptname.cgi

    David

    dave hj~

Re: Writing to a file
by hotshot (Prior) on Nov 21, 2001 at 14:10 UTC
    If you have apache server or something similar you can view his error log and access log, maybe it'll give you any clues about your problem, you can also use:
    print CGI::Dump();
    It'll print to your browser all the arguments the browser is sending to your CGI.
    Try to work out what is your problem more specifically and maybe then someone could help you more (no one will read all the code you posted), goodluck

    Hotshot