Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl commenting Script? 2

Status
Not open for further replies.

ETbyrne

Programmer
Dec 27, 2006
59
US
Hi, I'm new to Perl and I am reading a book on it.

I was wondering if anybody knew of a script that allows someone to comment on a page but, the same script can be used for multiple pages.

Thanks for all help!
-ETbyrne
 
Ok, this is what I got so far.
------------------------------
#(c) 2006-2007 Evan Byrne
#!/usr/bin/perl
use warnings;
use strict;
use CGI qw/:standard/;
$CGI::pOST_MAX = 1024 * 10; # max 10K posts
$CGI::DISABLE_UPLOADS = 1; # no uploads
my $name = param('name') or error('Enter a name');
my $comments = param('comments') or error('Enter some comments');
($name,$comments) = escapeHTML($name,$comments);

open(my $FH,">> or die "$!";
print $FH "<hr>Name: $name<br>Comments:<br>$comments<hr>\n";
undef $FH;

print "Location:
sub error{
my $error = shift;
print header,start_html,h1($error),end_html;
exit;
}
-----------------------------
My index.shtml and comments.pl are in the folder (I can run perl scripts anywhere on my host).

I'm still getting this message, can you see what I'm doing wrong?
---------------------------
CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:


Invalid argument at e:\0\74\38\237038\user\240783\htdocs\mywebs\tmportal\test\comments.pl line 12.



You don't know me.
 
use the machine path to the file, not the url:

open(my $FH,">>machine/path/to/comments.txt/") or die "$!";




- Kevin, perl coder unexceptional!
 
#(c) 2006-2007 Evan Byrne

copywriting my code under your name? [swords]

- Kevin, perl coder unexceptional!
 
That's considered rather bad form, isn't it? It's one thing to plagiarise stuff off the Net (I understand it's the way most homework is done these days), but trying to copyright it as well is a bit much.

We shall have to start posting all our code answers and tips under the GPL...

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Sorry about that, I make all my scripts off a file called "A_NEW" and it has that at the beginning. I'll take that off. :)

Back to subject: How do I figure out the machines path to comments.txt?

You don't know me.
 
this is probably the path:

e:\0\74\38\237038\user\240783\htdocs\mywebs\tmportal\test\comments.txt



- Kevin, perl coder unexceptional!
 
Now I'm getting this,
---------------------------------
CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:


Illegal octal digit '8' ignored at e:\0\74\38\237038\user\240783\htdocs\mywebs\tmportal\test\comments.pl line 11.
Unrecognized escape \h passed through at e:\0\74\38\237038\user\240783\htdocs\mywebs\tmportal\test\comments.pl line 11.
Unrecognized escape \m passed through at e:\0\74\38\237038\user\240783\htdocs\mywebs\tmportal\test\comments.pl line 11.
Scalar found where operator expected at e:\0\74\38\237038\user\240783\htdocs\mywebs\tmportal\test\comments.pl line 11, near "">>e:\0\74\38\237038\user\240783\htdocs\mywebs\tmportal\test\comments.txt\") or die "$!"
(Missing operator before $!?)
String found where operator expected at e:\0\74\38\237038\user\240783\htdocs\mywebs\tmportal\test\comments.pl line 12, near "print $FH ""
(Might be a runaway multi-line "" string starting on line 11)
(Missing semi
----------------------------------

I think I'll ask my host. He probobly knows.

You don't know me.
 
try this:

Code:
#!/usr/bin/perl
use warnings;
use strict;
use CGI qw/:standard/;
$CGI::POST_MAX = 1024 * 10; # max 10K posts
$CGI::DISABLE_UPLOADS = 1; # no uploads
my $name = param('name') or error('Enter a name');
my $comments = param('comments') or error('Enter some comments');
($name,$comments) = escapeHTML($name,$comments);

open(FH,'>>e:/0/74/38/237038/user/240783/htdocs/mywebs/tmportal/test/comments.txt') or die "$!";
print FH "<hr>Name: $name<br>Comments:<br>$comments<hr>\n";
close <FH>;

print "Location: [URL unfurl="true"]http://www.mywebsfree.com/tmportal/test/index.shtml\n\n";[/URL]

sub error{
my $error = shift;
print header,start_html,h1($error),end_html;
exit;
}

- Kevin, perl coder unexceptional!
 
Still not working, now I'm getting this...

CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:


Type of arg 1 to close must be HANDLE (not ) at e:\0\74\38\237038\user\240783\htdocs\mywebs\tmportal\test\comments.pl line 13, near ";"
Execution of e:\0\74\38\237038\user\240783\htdocs\mywebs\tmportal\test\comments.pl aborted due to compilation errors.



You don't know me.
 
crap, change this line:

close <FH>;

to:

close(FH);


- Kevin, perl coder unexceptional!
 
It prints the name! But, it doesn't print the comments.

Sooooooo close! I'm happy that this looks like it'll work. :)

You don't know me.
 
make sure the name of the textarea tag is "comments" (all lower case).

- Kevin, perl coder unexceptional!
 
I did, and they where the same.

_______________________________________

You don't know me.
 
open the comments.text file and see whats in it.

- Kevin, perl coder unexceptional!
 
These are its contents.

-----------------------------------

<hr>Name: Evan<br>Comments:<br><hr>
<hr>Name: Joe<br>Comments:<br><hr>
<hr>Name: Herb<br>Comments:<br><hr>

-----------------------------------

As you can see it copied the names, but not the comments.
Would it have anything to do with using single quotes?

_______________________________________

You don't know me.
 
hmm.... put a '#' at the beginning of this line:

#($name,$comments) = escapeHTML($name,$comments);

and retry the script.



- Kevin, perl coder unexceptional!
 
It works! I can't thank you enough for all your help KevinADC!

(I think a bunch of Perl programmers should get together and creat a site called something like "simple scripts" and make a bunch of simple CGI scrpts that do things like upload files, commenting and stuff.)

Oh, my book I got covers Perl, but not a lot of CGI, do you have any suggestions on a book on CGI with Perl?

_______________________________________

You don't know me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top