Re: die and exit

[email protected] (Gunnar Hjalmarsson)
Newsgroups perl.beginners.cgi
Message-ID <[email protected]>
Jeff Pang wrote:
> Does die call exit when it's excuted?
> If so,when I overwrote exit() function in my script,would die call this customized exit?
> 
> I gave a test,but didn't see die calling exit distinctly.

Neither did I.

But you can override die() directly.

     sub die {
         print "test die\n";
         CORE::die;
     }

and call it as

     &die;

or

     main::die;

or, probably better:

     use subs 'die';

     sub die {
         print "test die\n";
         CORE::die;
     }

     die;

Finally, this is another technique for overriding a built-in function:

     BEGIN {
         *CORE::GLOBAL::die = sub {
             print "test die\n";
             CORE::die;
         };
     }

     die;

The latter one also affects calls for die() from use()d and require()d 
modules.

HOWEVER, since you asked on a CGI list, I suspect that you really don't 
need to use any of the above methods. To have die messages appear in the 
browser you'd better do:

     use CGI::Carp 'fatalsToBrowser';

     die "test die";

HTH

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.