Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
January 28, 2010, 10:58 pm
rate this thread
I have this cgi code that sometimes forks depending on the
size of input. If there is an error, a subroutine called print_error
is called and this subroutine prints an error message and dies. If the
cgi forks and there is a child, then this error message is captured by
an eval statement and is printed to the log file. However, if the cgi
does not fork, there is an ugly software error message on the page. Is
there a way to die so that when the cgi forks, eval captures the error
message but at the same time there is no nasty software error when the
cgi doesn't fork? I guess the easiest way is to turn CGI::Carp off but
is there another way to exit/die?
Thanks a lot!
Re: How to make a cgi program "die" without a software error message being printed to page
fork returns a child process id if it forks, so you can know if you're
in the parent or in the child. Store it in a variable. Simply let the
error handler behave differently depending on what's in that variable.
You may want to use a dummy value in that variable in case you skip
forking, and thus, you actually are in the parent.
- » FAQ 4.44 How do I test whether two arrays or hashes are equal?
- — Next thread in » PERL Discussions
- » FAQ 3.18 How can I free an array or hash so my program shrinks?
- — Previous thread in » PERL Discussions