Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: change perl function in runtime

by LanX (Chancellor)
on Dec 03, 2012 at 15:19 UTC ( #1006894=note: print w/replies, xml ) Need Help??


in reply to change perl function in runtime

You need *globs to manipulate symbol table entries like package functions! ( see perlmod and perlsub)

Something like this should do

{ package A; local *x = sub { die "aaa" }; #run tests ... } # &x reset after leaving block

if you want to explicitly reset &x try to store the old coderef before.

$old_coderef = \&x; # run tests ... # do what you want ... # (but think about the omen ;-) *x = $old_coderef;

Cheers Rolf

Replies are listed 'Best First'.
Re^2: change perl function in runtime
by david2008 (Scribe) on Dec 03, 2012 at 15:41 UTC
    It works very well. This is real perl alchemy :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1006894]
help
Chatterbox?
[Discipulus]: 4 day Bach is too muche even for me
[Discipulus]: LA you know who is paco?
[Lady_Aleena]: Disc, nope.
[Discipulus]: ahi ahi ahi!!
[Lady_Aleena]: paco is a little over 2 years before my time.
[Discipulus]: you can try tachyon's iterative approach Re: Win32 Recursive Directory Listing
[Lady_Aleena]: I'm on Linux/
[beech]: isn't 2 year about standard recovery time for that kind of surgery?
[Discipulus]: if you hate FIle::Find

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (13)
As of 2017-04-23 20:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (432 votes). Check out past polls.