Jesper Noehr wrote:
> Hey list!
>
> I'm having a problem with overriding a sub in CORE::GLOBAL.
> I need to override exit(), and I'm doing that with:
>
> BEGIN { *CORE::GLOBAL::exit = sub { print "exit: ".shift; } };
>
> ..which works for the program itself.
>
> However! When I call exit() in a module used by my program, the module
> actaully calls 'exit()' in its original meaning, and NOT the one I defined
> myself. How do I get the module to treat exit() the way I defined it?
it works for me:
package Safer;
*CORE::GLOBAL::exit =
sub{ print STDERR "trying to exit from " . caller(0) . "\n"};
1;
__END__
package Wrapper;
use Exporter;
use Safer;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(exit);
sub exit{
exit;
}
1;
__END__
#!/usr/bin/perl -w
use strict;
use Wrapper qw(exit);
exit;
print STDERR "still alive\n";
__END__
prints:
trying to exit from Wrapper
still alive
maybe it's time to show some of your code?
david
--
sub'_{print"@_ ";* \ = * __ ,\ & \}
sub'__{print"@_ ";* \ = * ___ ,\ & \}
sub'___{print"@_ ";* \ = * ____ ,\ & \}
sub'____{print"@_,\n"}&{_+Just}(another)->(Perl)->(Hacker)
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>