Gossamer Forum
Home : General : Perl Programming :

problem with perl script

Quote Reply
problem with perl script
I've made a script and it comes up an error when I try to use it.
It's a simple form script, but this nasty error is stopping everything.
Here's the error:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, drift@page.no* and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.


Okey that's it. The * is a thing I added just to show that the email address isen't the one that came up.

Well, I'll post the script.
Have checked it, but I'm terrible at finding my own mistakes.
Here is it:

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


#!/usr/bin/perl -wT
print "Content-type:text/html\n\n";

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/\n/ /g;
$value =~ s/\r//h;
$value =~ s/\cM//g;
$FORM{$name} = $value;
}


$email = 'kbergem@hotmail.com';
$subjekt = "Ivar Script svar!";
$mailprog = '/usr/sbin/sendmail';

open (MAIL, "|$mailprog -t") or diesub("Kan ikke åpne $mailprog!\n");
print MAIL "To: $email\n";
print MAIL "Subject: $subjekt\n\n";

print MAIL <<EndHTML;
Ivar har fylt ut sjemaet og dette ville han ha:

Messenger: $FORM{'messenger'}
Ultra Wincleaner: $FORM{'wincleaner'}
KaZaA: $FORM{'kazaa'}
DivX: $FORM{'divx'}

Kommentaren:
$FORM{'kommentar'}

EndHTML

close(MAIL);


print <<StartHTML;
<html><head><title>Takk Ivar!</title>
</head>
<body>
<h2>Takk, Ivar!</h2><p>

Takk, onkel Ivar for at du fylte ut sjemaet!<br>
Det skal bli gjort!<br>
God tur til Afrika!
</body>
</html>

StartHTML

# Sub's
sub diesub {
my($errmsg) = @_;
print "<html><body>";
print "<h2>Error</h2>\n";
print "$errmsg\n";
print "</body></html>\n";
exit;
}



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

Think the error come out of the <<EndHTML; in the email posting.
Somebody tell me what I have done wrong.

AND I DON'T WANT TO USE CGI.PM! (Yet)
Quote Reply
Re: [perlman] problem with perl script In reply to
You should always check your error log first or login to your telnet account and do:

perl -cw script.cgi

The generic internal server error message is useless unfortunately.

Last edited by:

Paul: Jul 22, 2002, 11:06 AM
Quote Reply
Re: [perlman] problem with perl script In reply to
Are you trying to execute the script from the command line like: perl script.cgi

Cheers - Dan Cool

----
Cheers,

Dan
Founder and CEO

LionsGate Creative
GoodPassRobot
Magelln
Quote Reply
Re: [perlman] problem with perl script In reply to
Hello perlman,

Line 13 has a possible error : $value =~ s/\r//h; ??? Typo error near end.

should it not be : $value =~ s/\r//g; # changed h to g

You may also get a error : Too late for "-T" option at script.pl line 1.

depending on your perl installation.

Copying the script off the web page also created 2 errors :

1. Can't find string terminator "EndHTML" anywhere before EOF at script.pl line 27.

2. Can't find string terminator "StartHTML" anywhere before EOF at script.pl line 44.

due to hidden characters after EndHTML and StartHTML.

-- you may not have these errors.

Also note:

The email shown in the 500 error message is the email configured for the server host / virtual host.

Hope this helps.

Kode
Quote Reply
Re: [kode] problem with perl script In reply to
Ahh you try to encourage someone to find their own errors and what happens?...some nice person finds them for them Wink
Quote Reply
Re: [Paul] problem with perl script In reply to
Ooooops !

Nice ! Who me ?

Perlman should really go to www.activestate.com and download and install perl

for windows on his local machine and then he can use perl -Tcw in a command

window just like I just did to find the errors. [ perl -cw will throw the too late for T error.]

I use Active State's perl and Apache server for windows on 127.0.0.1 to play with perl on Win 98.

Edit plus as a text editor so I can save in Unix format for Ascii upload to linux.

I also forgot to mention the very basic 500 error due to file permissions not set correctly.

Thanks

Kode
Quote Reply
Re: [kode] problem with perl script In reply to
>>
I use Active State's perl and Apache server for windows on 127.0.0.1 to play with perl on Win 98.
<<

Ditto, except I use WinXP (I also installed the win version of mod_perl)

>>
Edit plus as a text editor so I can save in Unix format for Ascii upload to linux.
<<

Ditto again :)
Quote Reply
Re: [Paul] problem with perl script In reply to
Thank's folks!
I'll try to fix the mistakes!
And Paul, it's good that somebody tell's me the mistakes because I don't have access to the error log and can't use telnet!
Quote Reply
Re: [perlman] problem with perl script In reply to
You can install perl on your pc and do it using the command prompt :)
Quote Reply
Re: [kode] problem with perl script In reply to
I must admit that I diden't understand everything you you explained.....
First:
I fixed the stupid mistake : $value =~ s/\r//g;
Now I removed the -wT
Tried it, diden't work. (same error!)

But the thing I diden't understand was:
1. Can't find string terminator "EndHTML" anywhere before EOF at script.pl line 27.

2. Can't find string terminator "StartHTML" anywhere before EOF at script.pl line 44.

due to hidden characters after EndHTML and StartHTML.

Huh?
What should I do? I think I'n pretty good in english, but this I don't understand.
And I don't get that kind of error.

Can you please explain a bit easier?
So that we "stupid" people can understand....Unsure

And by the way, I knew the thing with the server host email address. Diden't want to show.

The thing you wrote in the next post.
About ActiveState and downloading perl on my machine. If I download that file(s), do I get perl on my machine? So that I can test perl scripts without uploading files on the internet?
I haven't really figured out what that is.....if you know what I mean.

I don't think I'm gonna download the file yet.
I'm getting a new(and much,much better) machine soon!
Thanks for all answers! (if they come!)
Quote Reply
Re: [perlman] problem with perl script In reply to
>>
But the thing I diden't understand was:
1. Can't find string terminator "EndHTML" anywhere before EOF at script.pl line 27.

2. Can't find string terminator "StartHTML" anywhere before EOF at script.pl line 44.
<<

You need to make sure StartHTML and EndHTML and right at the start of the line with nothing _before_ them....ie:

Code:
print <<StartHTML;

Foo

StartHTML

...will work...but:

Code:

print <<StartHTML;

Foo

StartHTML

...won't.

>>
About ActiveState and downloading perl on my machine. If I download that file(s), do I get perl on my machine? So that I can test perl scripts without uploading files on the internet?
<<

Yep...it comes as a simple windows installer:

http://www.activestate.com/...t.plex?id=ActivePerl
Quote Reply
Re: [Paul] problem with perl script In reply to
Somebody's talking my language!!
Thank you for all the help!
And kode!

It worked!!
Everything! The mail came!
Thank's again Paul!

- perlman (still learning! ;)
Quote Reply
Re: [perlman] problem with perl script In reply to
Why not use a module so you can see the errors in your browser as you cannot access the error log.

So add this green colored text right after the first line:

#!/usr/bin/perl -wT

# ensure all fatals go to browser during debugging and set-up
# comment this BEGIN block out on production code for security
BEGIN {
$|=1;
use CGI::Carp('fatalsToBrowser');
}


# all the rest of the code goes here.

Then you may see your errors in your browser.

===========

Start with a real simple hello world if this is your first script on this server.

try :

#!/perl/bin/perl -wT

# ensure all fatals go to browser during debugging and set-up
# comment this BEGIN block out on production code for security
BEGIN {
$|=1;
use CGI::Carp('fatalsToBrowser');
}

# all the rest of the code goes here

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

print "Hello, World... this script works \n";

======== Does it work ? or do you get an error ?

Thanks

Kode
Post deleted by perlman In reply to