Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Redefining Imported Subs: of scope and no

by LanX (Bishop)
on Feb 09, 2013 at 02:22 UTC ( #1017918=note: print w/replies, xml ) Need Help??


in reply to Redefining Imported Subs: of scope and no

Long read!

(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 = \&not_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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1017918]
help
Chatterbox?
[hippo]: Anyone able to get to https://deps. cpantesters.org/? Not even getting a connection from here.
[choroba]: Down for everyone of just me
[shmem]: "Problem loading page" here
[marto]: seems down
[planetscape]: Able to ping but not connect with either Opera or Firefox
[thanos1983]: same here...
[choroba]: marto ;-)
[Discipulus]: after an error now is back
[shmem]: looks like a 302 loop - "The document has moved here"

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (12)
As of 2018-02-20 11:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (271 votes). Check out past polls.

    Notices?