Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: change perl function in runtime

by grondilu (Pilgrim)
on Dec 03, 2012 at 15:44 UTC ( #1006900=note: print w/ replies, xml ) Need Help??


in reply to change perl function in runtime

EDIT: Please ignore this message, a good answer has been given above. You can alter the symbol table with *globs

The description does not really fit the title. In order to change a perl function in runtime, you would have to alter the symbol table. It can be done but it requires a lot of perl experience I think. Unless of course your function was defined as a reference to a function, in which case you can alter it as you would with any variable, which is trivial. Anyway I don't really see what you want to do.

It seems to me that what you really want is to just use 'eval':

package A; sub Y { die "aargh" } sub X { eval { Y }; if ($@) { print "humm... Y failed..." } { print "ok, no error here"; } }


Comment on Re: change perl function in runtime
Download Code
Replies are listed 'Best First'.
Re^2: change perl function in runtime
by ColonelPanic (Friar) on Dec 03, 2012 at 15:47 UTC
    The title is fine; you have misunderstood the question. Take a look at Rolf's solution.


    When's the last time you used duct tape on a duct? --Larry Wall

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1006900]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (15)
As of 2015-07-28 13:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (254 votes), past polls