Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Is modifying the symbol table to redefine subroutines evil?

by belden (Friar)
on Apr 14, 2007 at 00:33 UTC ( #610021=note: print w/ replies, xml ) Need Help??


in reply to Is modifying the symbol table to redefine subroutines evil?

Modifying the symbol table can be useful: at work we used a similar trick to write Test::Resub. (Its use is slightly different from what you're doing, but you might like to give its source a quick read.)

If call_me_only_once() really should only be called once, then why not solve the problem there instead of in its caller? (You've already seen how to enforce single execution by scoping a variable outside the sub.)

Addressing the problem there would mean you wouldn't need to worry about bar() making a call to call_me_only_once(); presumably your program knows the answer to that question already.

--Belden


Comment on Re: Is modifying the symbol table to redefine subroutines evil?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2015-08-01 00:17 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 (285 votes), past polls