Re: die and exit
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 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: die and exit
[ A while ago I commented on the same question in beginners-cgi, without knowing about the discussion here. Please do not multi-post!! http://lipas.uwasa.fi/~ts/http/crospost.html ] Jeff Pang wrote: Yes that's fine. I think when we say 'use Apache qw/exit/' in modperl scripts,it may do the same things as you mentioned -- modify the typeglob directly -- but I'm not so sure. In addition to all the other replies, and if die() in mod_perl is your actual concern, please read http://perl.apache.org/docs/1.0/guide/porting.html#die___and_mod_perl exit(), OTOH, is a mod_perl issue that needs to be addressed in older (pre 5.6) Perl versions. http://perl.apache.org/docs/1.0/guide/porting.html#Terminating_requests_and_processes__the_exit___and_child_terminate___functions -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: die and exit
In a message dated 2007-8-15 23:24:44 中国标准时间, [EMAIL PROTECTED] writes: In addition to all the other replies, and if die() in mod_perl is your actual concern, please read http://perl.apache.org/docs/1.0/guide/porting.html#die___and_mod_perl exit(), OTOH, is a mod_perl issue that needs to be addressed in older (pre 5.6) Perl versions. _http://perl.apache.org/docs/1.0/guide/porting.html#Terminating_requests_and_p rocesses__the_exit___and_child_terminate___functions_ (http://perl.apache.org/docs/1.0/guide/porting.html#Terminating_requests_and_processes__the_exit___and _child_terminate___functions) Hmm!You may need to see my original question,I just want to know if die calls exit in perl core. For mp1 document,yes,I don't think I know it too less.See this source with me, _http://perl.apache.org/docs/offsite/books.html#Practical_mod_perl_ (http://perl.apache.org/docs/offsite/books.html#Practical_mod_perl) ** Get a sneak peek of the all-new AOL at http://discover.aol.com/memed/aolcom30tour
Re: die and exit
On Aug 13, 2007, at 9:29 AM, 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? Do you want some code executed if the program dies? If that's the case assign a coderef to $SIG{__DIE__}: $SIG{__DIE__} = sub { my $message = shift; ... }; See %SIG in perlvar, and see the bottom of perldoc -f die. -- fxn -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: die and exit
-Original Message- From: Xavier Noria [EMAIL PROTECTED] Sent: Aug 13, 2007 3:43 AM To: beginners-list beginners@perl.org Subject: Re: die and exit On Aug 13, 2007, at 9:29 AM, 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? Do you want some code executed if the program dies? No.I just want to see if die call exit in perl core. I saw scripts under modperl import Apache::exit but don't import something like Apache::die.So I think maybe die has called exit when it excuted. -- Jeff Pang [EMAIL PROTECTED] http://home.arcor.de/jeffpang/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: die and exit
there is a difference between the function exit: perldoc -f exit and a sub you have defined by your own. even if you re-use a name of a build-in. thats why you called exit via exit; and not exit; or exit(); #!/usr/bin/perl -w sub exit(){ print sub exit called\n; } exit; exit(); if ($ARGV[0] == 1) { exit; # way 1 }else { exit(); # way 2 } [EMAIL PROTECTED] ~ % perl pang.pl 1 Ambiguous call resolved as CORE::exit(), qualify as such or use at pang.pl line 11. Ambiguous call resolved as CORE::exit(), qualify as such or use at pang.pl line 13. sub exit called sub exit called [EMAIL PROTECTED] ~ % perl pang.pl 2 Ambiguous call resolved as CORE::exit(), qualify as such or use at pang.pl line 11. Ambiguous call resolved as CORE::exit(), qualify as such or use at pang.pl line 13. sub exit called sub exit called -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: die and exit
-Original Message- From: Paul Lalli [EMAIL PROTECTED] Sent: Aug 13, 2007 7:06 PM To: beginners@perl.org Subject: Re: die and exit On Aug 13, 3:29 am, [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? sub exit { print test exit; exit; } This does not overwrite exit. Your own subroutine exit and the built-in CORE::exit() are not the same thing. Then how to overwrite CORE::exit? Can anybody help explain how Apache::exit overwrite CORE::exit? -- Jeff Pang [EMAIL PROTECTED] http://home.arcor.de/jeffpang/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: die and exit
On Aug 13, 3:29 am, [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? sub exit { print test exit; exit; } This does not overwrite exit. Your own subroutine exit and the built-in CORE::exit() are not the same thing. Paul Lalli -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: die and exit
On Mon, Aug 13, 2007 at 07:24:56PM +0800, Jeff Pang wrote: sub exit { print test exit; exit; } This does not overwrite exit. Your own subroutine exit and the built-in CORE::exit() are not the same thing. Then how to overwrite CORE::exit? Can anybody help explain how Apache::exit overwrite CORE::exit? $ perl -le 'BEGIN { *CORE::GLOBAL::exit = sub { print 42 } } exit; print 99' 42 99 -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: die and exit
-Original Message- From: Paul Johnson [EMAIL PROTECTED] Sent: Aug 13, 2007 7:45 PM To: Jeff Pang [EMAIL PROTECTED] Cc: Paul Lalli [EMAIL PROTECTED], beginners@perl.org Subject: Re: die and exit On Mon, Aug 13, 2007 at 07:24:56PM +0800, Jeff Pang wrote: sub exit { print test exit; exit; } This does not overwrite exit. Your own subroutine exit and the built-in CORE::exit() are not the same thing. Then how to overwrite CORE::exit? Can anybody help explain how Apache::exit overwrite CORE::exit? $ perl -le 'BEGIN { *CORE::GLOBAL::exit = sub { print 42 } } exit; print 99' 42 99 Yes that's fine. I think when we say 'use Apache qw/exit/' in modperl scripts,it may do the same things as you mentioned -- modify the typeglob directly -- but I'm not so sure. Thanks. -- Jeff Pang [EMAIL PROTECTED] http://home.arcor.de/jeffpang/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: die and exit
On Aug 13, 2007, at 1:57 PM, Jeff Pang wrote: Yes that's fine. I think when we say 'use Apache qw/exit/' in modperl scripts,it may do the same things as you mentioned -- modify the typeglob directly -- but I'm not so sure. I don't know too much XS but looks like this code in src/modules/perl/ mod_perl.c does that (the comment says so as well): /* *CORE::GLOBAL::exit = \Apache::exit */ if(gv_stashpv(CORE::GLOBAL, FALSE)) { GV *exitgp = gv_fetchpv(CORE::GLOBAL::exit, TRUE, SVt_PVCV); GvCV(exitgp) = perl_get_cv(Apache::exit, TRUE); GvIMPORTED_CV_on(exitgp); } -- fxn -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: die and exit
Thank you.That explained what I want to know. --Jeff Pang ** Get a sneak peek of the all-new AOL at http://discover.aol.com/memed/aolcom30tour
Re: die and exit
Jeff Pang wrote: From: Xavier Noria [EMAIL PROTECTED] On Aug 13, 2007, at 9:29 AM, 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? Do you want some code executed if the program dies? No.I just want to see if die call exit in perl core. I saw scripts under modperl import Apache::exit but don't import something like Apache::die.So I think maybe die has called exit when it excuted. perldoc -f die die LIST Outside an eval, prints the value of LIST to STDERR and exits ^ with the current value of $! (errno). If $! is 0, exits with the ^ value of ($? 8) (backtick ‘command‘ status). If ($? 8) is 0, exits with 255. Inside an eval(), the error message is ^ stuffed into $@ and the eval is terminated with the undefined value. This makes die the way to raise an exception. perldoc -f exit exit EXPR exitEvaluates EXPR and exits immediately with that value.Example: $ans = STDIN; exit 0 if $ans =~ /^[Xx]/; See also die. John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order.-- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: die and exit
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? See the section Overriding Built-in Functions in: perldoc perlsub John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order.-- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/