in reply to Overriding exec globally
When you use require, the code will execute too late. The BEGIN {} within the module doesn't achieve the desired result, because it won't be seen before the require loads the file at runtime, at which time the exec statement has already been compiled.
Just make a proper .pm module of it and use it in the main script (which implies BEGIN {}):
package execOverride; # execOverride.pm *CORE::GLOBAL::exec = sub { my $cmd = shift; print "Called exec override\n"; CORE::exec($cmd); }; 1; # main script #!/usr/bin/perl use execOverride; exec("/bin/echo foo"); __END__ $ ./830161.pl Called exec override foo
(btw, the package statement isn't really needed here, but it doesn't do any harm either)
|
|---|