rpike has asked for the wisdom of the Perl Monks concerning the following question:

I've got this large script (CGI app written in Perl) that basically goes through various files of data in order to generate a schedule for staff members. In one of the larger loops the script seems to just die. There is no feedback from the browser (blank page), no errors display, etc..,. I'm using the CGI module to grab the values from the form response. Any idea what could be causing this problem? I've checked the loops and if they were somehow infinite the browser would keep chugging along. There are no exits or premature returns in place to make it look like the script has indeed finished. I'd appreciate any help on this one. Thanks.

Replies are listed 'Best First'.
Re: Application just dies
by zentara (Cardinal) on Feb 27, 2009 at 16:38 UTC
    If you have access to the server logs, you should check that for errors after running your script. You should have log access somewhere in your Control Panel, or server-computer's filesystem.

    You can also put

    use CGI::Carp qw(fatalsToBrower);
    at the top of the cgi script. It is a security risk though to send errors over http, so remove that line when you get it working.

    I'm not really a human, but I play one on earth My Petition to the Great Cosmic Conciousness
Re: Application just dies
by Herkum (Parson) on Feb 27, 2009 at 19:23 UTC

    Try running your script on another version of Perl. Preferably a more current version.

    Every once in a while I encounter a compiled version of Perl that blows up for some strange reason on perfectly normal code. No rhyme or reason for it, but it does happen. When it gets to this point my only option was to try another version of Perl. Try an upgraded version on the current box or the same version on another box (different OS).

Re: Application just dies
by rpike (Scribe) on Feb 27, 2009 at 16:44 UTC
    I already have the fatalsToBrowser in. Still no error coming back. The browser stops loading the page after about 2 seconds. That section of code normally takes longer. I had this sub where this large loop takes place. I commented out almost everything in the loop except about 20 lines of code and it did run. What I've tried since was wrapping the call to that sub in a loop itself (1 to 100) to see if calling the sub (with just a few lines) would kill the script as before. It did. I put in the outer loop a check to exit if the outer loop hit a certain iteration. Looks like it dies each time on the 5th iteration. There's hardly anything in the sub now so why it fails has me puzzled. Any ideas? Thanks by the way for the response.

      There are about a gazillion of possibilities why a script might simply terminate prematurely without producing an error, i.e. not produce any content (blank page)... — Without seeing the code, it's hard to come up with specific help :)

      Try putting in print statements at various places in your script to narrow down on where/when it quits.

      Does the script work when run from the commandline? What error does it die width? You can test cgi scripts from the commandline, google for "perl cgi test commandline".

      I'm not really a human, but I play one on earth My Petition to the Great Cosmic Conciousness
Re: Application just dies
by boblawblah (Scribe) on Feb 27, 2009 at 17:10 UTC
    An example of your code would really help us answer your question...

    Don't forget to use <code></code> tags.
Re: Application just dies
by rpike (Scribe) on Feb 27, 2009 at 21:24 UTC
    Okay here's another one. After the loop I put in a line to print to the browser. Just an ole print "Made it here"; exit(0);. Nothing prints to the screen and the browser finishes loading, like before. I put in an open file and write to it and then after that I open the file at key points, write to it a specific string to say it had been there (concatenated), and then I close the file. When I go in and look at the file generated it shows me it reached the point of where I put the print and exit. What the heck would be causing this to happen? It looks as though the program does reach that point but no feedback is coming back from the web server. Not much good considering it's a CGI application. Any help would be greatly appreciated.

      When what you describe is correct, it looks as if your webserver (or something from webserver to browser (proxy?)) is having buffering issues. (BTW, do you declare your content as text/plain?)

      What happens if you run the CGI program from the commandline (if that's possible)? Is your "Made it here" missing, too, then, from stdout output?

Re: Application just dies
by rpike (Scribe) on Mar 02, 2009 at 13:57 UTC
    I'm using the CGI module in the script to grab form values. Since this section of code only gets hit when certain things are passed how can I make a mock URL call to the script from DOS? I tried doing scriptname?name1=val1&name2=val2 but it complains that name1 is not recognized as an internal or external command and the same with every "name" afterwards. Is there a way to do this without having to change the script itself? The script runs fine from DOS but isn't hitting the same key areas as if from the browser. Sorry I didn't get back earlier but thanks so much for the response(s).

      Read CGI about debugging your CGI script from the command line.

Re: Application just dies
by rpike (Scribe) on Feb 27, 2009 at 18:04 UTC
    It's one of the first things I always do (breakpoints = print statements). I believe I see where the problem lies. There's a section whereby a scalar is set to $hash{$variableIn}{"NoUsers"} and then that scalar is used in a comparison statement (i.e. =~ /^(0-9)$/). It may be that there is no entry for variable at a certain time in the loop. I'll try a defined if and see if that fixes it before posting back. Thanks again.
Re: Application just dies
by rpike (Scribe) on Feb 27, 2009 at 18:25 UTC
    I can't recall ever getting this before but the nature of the application I have the loops set up differently. If I were to have an array of 40 long (0-39) but used a loop from 0-50 what would happen normally if you try and access the 40 to 50th elements of the array? Normally I have the loop condition based on the max limit of the array. Thanks.
      If I were to have an array of 40 long (0-39) but used a loop from 0-50 what would happen normally if you try and access the 40 to 50th elements of the array?

      With read access, you'd get an undef value, and with write access, the element at the respective index would be set to whatever you set it to (with automatic resizing of the array, under the hood).