Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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

by NetWallah (Abbot)
on Apr 11, 2007 at 23:33 UTC ( #609525=note: print w/replies, xml ) Need Help??


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

Assuming code-tampering is not an issue, how about this:
my $foo; # Global, because this is the only visible (subroutine ref) $foo=sub{ print qq[First call - do first processing here \n]; # First processing code goes here ... # Now setup for subsequent calls .... $foo=sub{ print qq[subsequent calls\n] # Code for subsequent calls goes here } }; $foo->() for 0..5; # OK - so the subroutine call looks slightly weird +to newbies.
Unfortunately, Murphy's laws will kick in if the caller decides to use a copy/clone of the $foo scalar, so don't do that.

     "Choose a job you like and you will never have to work a day of your life" - Confucius

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://609525]
help
Chatterbox?
[LanX]: shmem: ah I see ... you'll need to check if the monastery standard classes come with border ... like the nodelets should
[karlgoethebier]: shmem: you could have linked to jackass as well ;-)
[stonecolddevin]: morning all
[shmem]: karlgoethebier: better choice, done. :-)

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (11)
As of 2017-07-24 17:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (356 votes). Check out past polls.