Gossamer Forum
Home : General : Perl Programming :

MOD - Non Gossamer

Quote Reply
MOD - Non Gossamer
Hi All.

Eliot (the Great) has been helping me with a perl/cgi script I've been trying to get working.

You can view our discussion at: www.gossamer-threads.com/scripts/forum/resources/Forum12/HTML/002029.html


I followed his directions, and when I uploaded/chmoded the script, I got two errors. One I fixed, the other I can't figure out.

Here is the error message I get:
Quote:
syntax error at oneliner.cgi line 162, near "open"
Execution of oneliner.cgi aborted due to compilation errors.

Here is lines 158-166 (in my code):
Quote:
sub submit_success
#-------------------------------------------
# Submits data

open(DB, ">$filename") or die &PrintErrorPage("Can't write to file '$filename'\n");
print DB '<tr bgcolor="' . $bgcolor . '">';
print DB '<td align=left nowrap>' . $font_date . &GetDateString . '</font></td>';
print DB '<td align=left nowrap>'.$font_msg . $in{'msg'} . '</font></td>';
print DB '<td align=right nowrap>'.$font_who . $in{'who'} . '</font></td>';

With line 162 being:
Quote:
open(DB, ">$filename") or die &PrintErrorPage("Can't write to file '$filename'\n");

It seems that something on this line is not correct, but I've tried a few dozen different things.. I'm just learning perl/cgi (as I go along) so, I could be looking right over something!

Any ideas?

JbA

------------------
John B. Abela
Owner, 4CM
www.4cm.com/
support@4cm.com

Presently working on:
www.humbee.com/buzz/



[This message has been edited by Yokhannan (edited January 29, 2000).]
Quote Reply
Re: MOD - Non Gossamer In reply to
Change:

open(DB, ">$filename") or die &PrintErrorPage("Can't write to file '$filename'\n");

to:

open(DB, ">$filename") or &PrintErrorPage("Can't write to file '$filename'\n");


Dan Smile
Quote Reply
Re: MOD - Non Gossamer In reply to
Hi Dan.

Thanks for the suggestion.

However, I'm still getting the same error message.

Code:
#!/usr/local/bin/perl
#
# Oneliner
#
# Copyright (c) Stefan Pettersson 2000
#
# You may not redistribute this script, but it's free to use.
#
# Version History:
# v0.9 2000-01-26 - Initial public beta version.
#
# For further information see:
# http://www.stefan-pettersson.nu/scripts/
#
##############################################################################

# Filename to write the messages to. This file is then included by a HTML page.
$filename = '/export/www/humbee/humbee/oneliner/oneliners_incl.html';

# How many message should be displayed at once
$number_of_rows = 8;

# How the date and time will be displayed
$dateformat = '[monthnameshort] [day], [hour0]:[min0] [ampm]';

# Names of weekdays
@daynames = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday);

# Names of months
@monthnames = qw(January February March April May June July August September October November December);

# Background color of the entered messages, specified in hex as in HTML
$bgcolor = '#000000';

# Font tag to use for date
$font_date = '<font face="tahoma, verdana, arial, geneva" size=1 color="#4FE59D">';

# Font tag to use for the actual message
$font_msg = '<font face="tahoma, verdana, arial, geneva" size=1 color="#EFEF80">';

# Font tag to use for the nickname
$font_who = '<font face="tahoma, verdana, arial, geneva" size=1 color="#EF80EF">';

# Dirty Word Censor
@dirty_words = ('@!#$','@!#$','cocksucker','@!#$','cunt','pussy','tits','bastard','bitch','piss','fuck','ass');

# You do not need to modify anything below this line.

##############################################################################

&ReadParse;

## ADDED FOR 'DIRTY WORD' CODE
$bwords = $in{'who'};
$bwords2 = $in{'msg'};
foreach $bwords (@dirty_words) {
if ($in{'who'} =~ / $bwords/i) {
&submit_error;
return;
}
}
foreach $bwords2 (@dirty_words) {
if ($in{'msg'} =~ / $bwords2/i) {
&submit_error;
return;
}
}
if ($in{'who'} ne "" && $in{'msg'} ne "") {
if (-e $filename) {
open(FILE, $filename) | | die $!;
@lines = <FILE>;
close(FILE);
}
&submit_success;
}

## END 'DIRTY WORD' CODE


##############################################################################

sub GetDateString {
my $formatstring = $dateformat;
my %datestr;
my ($sec, $min, $hour, $day, $month, $year, $weekday) = localtime($^T);

$datestr{'sec'} = $sec;
$datestr{'sec0'} = sprintf("%02d", $sec);

$datestr{'min'} = $min;
$datestr{'min0'} = sprintf("%02d", $min);

$datestr{'hour24'} = $hour;
$datestr{'hour240'} = sprintf("%02d", $hour);

$datestr{'ampm'} = ($hour > 12) ? 'pm' : 'am';

$hour -= 12 if $hour > 12;
$hour = 12 if ($hour == 0);

$datestr{'hour'} = $hour;
$datestr{'hour0'} = sprintf("%02d", $hour);

$datestr{'day'} = $day;
$datestr{'day0'} = sprintf("%02d", $day);

$datestr{'dayname'} = $daynames[$weekday];
$datestr{'daynameshort'} = substr($daynames[$weekday], 0, 3);

$datestr{'month'} = $month + 1;
$datestr{'month0'} = sprintf("%02d", $month + 1);
$datestr{'monthname'} = $monthnames[$month];
$datestr{'monthnameshort'} = substr($monthnames[$month], 0, 3);

$datestr{'year'} = 1900 + $year;
$datestr{'shortyear'} = sprintf("%02d", $year % 100);

while ($formatstring =~ /\[([^\]]+)\]/) {
my $tag = $1;
$formatstring =~ s/\[$tag\]/$datestr{$tag}/;
}

return $formatstring;
}

##############################################################################

sub ReadParse {
my $buf, @pairs;

if ($ENV{'REQUEST_METHOD'} eq 'GET') {
@pairs = split(/&/, $ENV{'QUERY_STRING'});
} elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN, $buf, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buf);
}

foreach (@pairs) {
local($key, $val) = split(/=/);

$key =~ tr/+/ /;
$val =~ tr/+/ /;

$key =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$val =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

# Strip dangerous characters, removes HTML and SSI for example
$val =~ s/<([^>]|\n)*>//g; # Strip SSI and HTML

$in{$key} = $val;
}
}

#################################################################
# 'Dirty Word' MOD

sub submit_success
#-------------------------------------------
# Submits data

open(DB, ">$filename") or &PrintErrorPage("Can't write to file '$filename'\n");
print DB '<tr bgcolor="' . $bgcolor . '">';
print DB '<td align=left nowrap>' . $font_date . &GetDateString . '</font></td>';
print DB '<td align=left nowrap>'.$font_msg . $in{'msg'} . '</font></td>';
print DB '<td align=right nowrap>'.$font_who . $in{'who'} . '</font></td>';
print DB "</tr>\n";
for ($i = 0; $i < $number_of_rows - 1; $i++) {
print DB $lines[$i];
}
close(DB);
}
&thank_you;
exit;
}


sub submit_error {
#--------------------------------------------
# Error Message
print "Content-type: text/html\n\n";
print qq|
<html>
<head>
<title>Submission Error</title>
</head>
<body bgcolor="ffffff">
<center>
<h1>Submission Error</h1>
</center>
<br>
You have posted inappropriate language in one of the fields. Use your back button in your browser to fill out the form again.
</body>
</html>
|;
}


sub thank_you {
#--------------------------------------------
# Error Message
print "Content-type: text/html\n\n";
print qq|
<html>
<head>
<title>Thank you!</title>
</head>
<body bgcolor="ffffff">
<center>
<h1>Thank you!</h1>
</center>
<br>
Thank you for submitting your message.
</body>
</html>
|;
}


######################
## End Dirty Word MOD
######################

##############################################################################

sub PrintErrorPage {
print "Content-type: text/html\n\n";

print "<html><head><title>Script error!</title></head><body>";
print "<b>Script error!</b><p>\n";
print $_[0];
print "</body></html>";
}

?? any thoughts?

JbA

[This message has been edited by Yokhannan (edited January 29, 2000).]
Quote Reply
Re: MOD - Non Gossamer In reply to
Again, following dan's advice...change the following codes:

Code:
open(FILE, $filename) | | die $!;

to the following:

Code:
open(FILE, ">$filename") or &PrintErrorPage("Can't write to file '$filename'\n");

Also, you know what I would do is delete the following codes:

Code:
if (-e $filename) {
open(FILE, $filename) | | die $!;
@lines = <FILE>;
close(FILE);
}

You are already checking for the database in the sub submit_success routine.

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
* Be sure to visit the Resource Center for FAQ's, Modifications and Extra Goodies!!
* Search Forums!
* Say NO to Duplicate Threads. :)
----------------------








Quote Reply
Re: MOD - Non Gossamer In reply to
Hi Guys...

still nothing....

I sware... I've tried every possible solution I can think of... I've added, I've deleted, I've changed... I'm about to give up... this is just a really stupid little script... Just thought I'd use it as the base for setting up 'dirty word' in other scripts... I don't know.... aahhhhhh!

O'well.

Thanks for trying guys!

JbA
Quote Reply
Re: MOD - Non Gossamer In reply to
What do you mean...still nothing? Are you getting error messages? What?

Try adding return; after the following codes:

Code:
&submit_success;

like the following:

Code:
&submit_success;
return;

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
* Be sure to visit the Resource Center for FAQ's, Modifications and Extra Goodies!!
* Search Forums!
* Say NO to Duplicate Threads. Smile
----------------------










[This message has been edited by Eliot (edited January 29, 2000).]
Quote Reply
Re: MOD - Non Gossamer In reply to
Eliot.

Yes, I added the:

return;

Awhile back I spotted it... figured it should be in there...

As for What do you mean...still nothing? Are you getting error messages? What?

I am still getting that same "syntax error" message. Near the "open" command.

Man, I've tried everything I can think of...
I've totally removed sections... I've changed the "DB" to "FILE"... (just for the he-he of it)... Everytime, I'm getting the error message:

Quote:
syntax error at oneliner.cgi line, 16x, near "open"
Execution of oneliner.cgi aborted due to compilation errors.

(line 16x being where ever that one line is, depending upon what lines I add/remove)

The line that is causing the problem is:
Quote:
open(DB, ">$filename") or &PrintErrorPage("Can't write to file '$filename'\n");

Or however, I happen to rewrite it.

Later Eliot.
Quote Reply
Re: MOD - Non Gossamer In reply to
hi Yokhannan,

i could be wrong, this is your line now:

open(DB, ">$filename") or &PrintErrorPage("Can't write to file '$filename'\n");

Maybe the error is the "Can't", since the ' is also interpreted as a quote. you can try to change it to:

open(DB, ">$filename") or &PrintErrorPage("Can not write to file '$filename'\n");

which i hope should work.

greetings from austria!
Quote Reply
Re: MOD - Non Gossamer In reply to
sub submit_success

You're missing the { to start the subroutine.

#-------------------------------------------
# Submits data
open(DB, ">$filename") or &PrintErrorPage("Can't write to file '$filename'\n");

*snip*

}
&thank_you;
exit;
}

You may have an extra closing brace there.

Always keep in mind, just because it reports a syntax error on one line, it is not necesarrily on that line. always look right above.

--mark
Quote Reply
Re: MOD - Non Gossamer In reply to
Hi All.

Well, Mark, you've hit it on the head! Smile

dang... talk about feeling like a retard!...

Ah... well, the little error message has gone ways, and it will now run.

However, I do have one other little problem.

It is only showing one (1) line, of subitted data. It should show XYZ amount of lines, based upon the :

$number_of_rows = 8;

Setting.


Any thoughts on why it's only showing one (1) line, and not eight (8)?


Thanks All!!
JbA
Quote Reply
Re: MOD - Non Gossamer In reply to
Oops...I missed the obvious! Good catch, Mark! And also great piece of advice.

With regards to your problem, I don't have time to look over your codes. May be later today.

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
* Be sure to visit the Resource Center for FAQ's, Modifications and Extra Goodies!!
* Search Forums!
* Say NO to Duplicate Threads. :)
----------------------