in reply to same 500 server error problem shorter question

Here's the gig :
Sometimes I get caught up in fixing errors in CGI scripts, and my mind opens up to the dozens and dozens of components that interact with each other to bring my customers the hot-hot CGI action they expect of me.
I think about the apache servers, the iis servers, the domino and notes servers, the linux boxes, the NT and win2000 boxes, e-mail gateways, routers and trunks, all of the scripts that I've written and that others have written and how we've improved and changed them, maybe docmenting, manybe not, and all of the possible and horrible interactions they could have. In my mind, I picture them all working like a giant wheat thresher, cutting and spinning, hulling and seperating and working at a frightening pace.
After a few moments of terrifying myself in this fashion, I start debugging.

What web server are you using?
Have you checked the logs?
Perhaps you don't have access to the web server or its logs; this is not entirely uncommon, as I understand it.

But understand that even though the script is meant to run through CGI, you still have ways of testing the script. Chief and most basic among these means is perl -c script.pl. The -c switch will not attempt to run script.pl, but simply test its syntax and return its 'compilability".

Running this against your script, I see

syntax error at C:\script.pl line 15, near "result substr"
perhaps you meant return substr $start, length $line;?

Also, please, for your own sake, add a die clause to your open line : open FILE, "user/test" || die "Can't open file! Perl says '$!'".

Talk with your web server admin and see if you can get access to the log files. If not, learn to rely on CGI's command line mode, or set up a similar server on a machine you control.

Replies are listed 'Best First'.
Re: (boo) debug-fu!
by virtualsue (Vicar) on Jun 07, 2001 at 12:55 UTC
    Also, please, for your own sake, add a die clause to your open line : open FILE, "user/test" || die "Can't open file! Perl says '$!'".

    Better make it

    open FILE, "user/test" or die "Can't open file! Perl says '$!'"; or open (FILE, "user/test") or die "Can't open file! Perl says '$!'"; or open (FILE, "user/test") || die "Can't open file! Perl says '$!'";
    This is probably one of the most commonly committed Perl coding errors, made by novices and the reasonably adept alike. In the case of
    open FILE, "filename" || die $!;  #ERROR - DON'T USE THIS the || version of 'or' tries to evaluate the thing immediately to its left, which is the the filename argument, "filename". Since that string always evaluates to true (in the boolean sense), the die will NEVER be executed, even if the  open fails. The or operator has a lower precedence than ||, so it can be used without parenthesis. I suggest using or for short-circuit error checks. Providing the args to open & die are correct, it will always do the right thing.