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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to debug CGI (Perl) programs

Status
Not open for further replies.

drfragment

Programmer
Sep 25, 2006
7
SI
Hi.

I can't send a "personal message" in my forum.
All I get is a blank page. Try it: (I've made a temporary test account: "tester", with pass: yxc".)

The forum (YaBB - http://yabbforum.com/) is written in Perl. It's a project, so debugging isn't so easy.
But actually, I don't want to remove the bug yet (the bug doesn't come with the original forum, but with some mods, I guess), what I do want to do is, to FIND the location in code at which program "stops", or gets thrown out of procedure (remember the blank page).
So, how do I do that?
 
You could write entries to a log file in the areas where you think it might be crashing.
 
there must be a YABB support forum that could help you.
 
debugging begins by turning on warnings and checking the server error logs. You turn on warnings by putting:

use warnings;

at the beginning of the script. or -w at the end of the shebang line:

#!/usr/bin/per -w

run the script then check the server error logs.
 
I've got into the habit of using this in EVERY script I write.

Code:
use CGI::Carp qw(fatalsToBrowser warningsToBrowser); 
use warnings;
use strict;

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
got it. I used your advice 1DMF.
Here the output:

Software error:

Global symbol "$subsplver" requires explicit package name at ./Sources/Subs.pl line 28.
BEGIN not safe after errors--compilation aborted at ./Sources/Subs.pl line 30.


Software error:

[Tue Sep 26 11:53:33 2006] YaBB.pl: Global symbol "$subsplver" requires explicit package name at ./Sources/Subs.pl line 28.
[Tue Sep 26 11:53:33 2006] YaBB.pl: BEGIN not safe after errors--compilation aborted at ./Sources/Subs.pl line 30.
Compilation failed in require at YaBB.pl line 56.

 
here's the line: $subsplver = 'YaBB 2.1 $Revision: 1.15 $';
 
I have no idea what "explicit package name" should it use ...
 
it seems that the $subsplver variable is not being declared, now you could run into a real massive problem using the "use srtict;" if none the code in the script is using "good practices".

basically if you want to use a variable you must declare it so the above line should be...
Code:
[b]my[/b]  $subsplver = 'YaBB 2.1 $Revision: 1.15 $';

however, if you start running into a whole host of these errors, to find the one your looking for remove or comment out the "use strict" for the time being, without being able to look at your PERL source it's hard to say if the code is very "STRICT" compliant or not!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
ok. But do you really think that this variable is the true problem? I found one in for statement. It doesn't go all the way. It stops at 122, while it should go to 140. How do I find the out the line which is causing problems? I don't want to check every line by hand because there are more then one hundred lines within "for" ...
 
There is no way for any of us to know if that is the one and only problem. Add the "my" and try the code again and see what happens.
 
I did. I just got a bunch of strange errors.
Anyway, I've transfered the whole forum to my local Window$ web server, and it worked!

That means, that probably I have the permissions set wrong somewhere. Heck, I used the their "official" chmod script . Do you see anything strange about permissions in this script?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top