Sorry about that. I hit reply and didn't notice it had your address in there 
rather than the list's.

Since I've never seen this program hang, I want to be notified any time it 
hangs, no matter who the user is. I found two options in the perldoc for 
CGI::Carp --

        1.    BEGIN {
        2.      use CGI::Carp qw(carpout);
        3.      open(LOG, ">>/usr/local/cgi-logs/mycgi-log") or
        4.        die("Unable to open mycgi-log: $!\n");
        5.      carpout(LOG);
        6.    }
Looks like I could put an error log just about anywhere on the server I could 
write
a path to.

        1.     use CGI::Carp qw(set_die_handler);
        2.     BEGIN {
        3.        sub handle_errors {
        4.           my $msg = shift;
        5.           print "content-type: text/html\n\n";
        6.           print "<h1>Oh gosh</h1>";
        7.           print "<p>Got an error: $msg</p>";
        8. 

        9.           #proceed to send an email to a system administrator,
        10.           #write a detailed message to the browser and/or a log,
        11.           #etc....
        12.       }
        13.       set_die_handler(\&handle_errors);
        14.     }
It would be WONDERFUL to get an email every time it glitched! Does anybody have 
a 


sub written for that?
John M Rathbun MD




________________________________
From: Jim Gibson <jimsgib...@gmail.com>
To: Perl Beginners <beginners@perl.org>
Sent: Sat, September 15, 2012 9:00:35 PM
Subject: Re: My long script

Please use the list for postings. That way, everybody gets to see your post. I 
am responding via the list.

On Sep 15, 2012, at 4:49 PM, jmrhide-p...@yahoo.com wrote:

> OK, interesting supposition that needs to be tested. I could just replace 
> every 
>while (1) with a for (1..10) as insurance, but I'm interested in knowing if a 
>particular instance of while (1) is the problem. How would you suggest I could 
>trap that error?

You can use the CGI::Carp module to write error messages to the HTML output 
page:

  use CGI::Carp qw( fatalsToBrowser );

and then use a loop of the form

  for my $i ( 1..10 ) {
    … # your code
    die("Loop 17 did not complete") if $i >= 10;
  }

That will put an error message into your output page.

If you are not the one triggering the error, then you will not see the message.

If you want to see anybody's message, you can open a file for logging error 
messages and write to it within your program when an error occurs. Where you 
open the log file depends upon your server environment.


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/

Reply via email to