For Programmers: Free Programming Magazines  


Home > Archive > PERL CGI Beginners > August 2007 > die and exit









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author die and exit
Jeff Pang

2007-08-13, 9:55 pm

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.

This works as I wanted:
use strict;
use warnings;

sub exit {
print "test exit";
exit;
}

&exit;


But this won't:
use strict;
use warnings;

sub exit {
print "test exit";
exit;
}

die;


Glad to hear any words from you.

--
Jeff Pang <pangj@earthlink.net>
http://home.arcor.de/jeffpang/
Gunnar Hjalmarsson

2007-08-15, 6:55 pm

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

¨

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
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com