in reply to Redefining Imported Subs: of scope and no
(wont try it again! ;-)
I don't understand why you're using feature qw(say) if you wanna redefine 'say.
This makes say() a builtin which has to be overridden like described in perlsub#Overriding Built in Functions.
Otherwise this works:
$verbose=0; sub not_say { print 'not saying'; } sub say { print @_,"\n"; } { no warnings; *say = \¬_say if not $verbose; } say 'test';
or even simpler:
use strict; use warnings; no feature "say"; sub say { print "nothing"; } say 'test';
OTOH you will certainly have problems if someone manages to globally switch say on.
My suggestion is to replace say() with something like 'log()' or 'out()' and keep it simple, don't redefine the sub at all, just put the test condition into the function body.
Cheers Rolf
|
|---|