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

changing source code in run time

by Anonymous Monk
on Jun 20, 2011 at 09:54 UTC ( #910542=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

is there any option available to change source code of a perl script in Runtime? The changes should be reflected in the running script.

Replies are listed 'Best First'.
Re: changing source code in run time
by planetscape (Chancellor) on Jun 20, 2011 at 10:28 UTC
Re: changing source code in run time
by moritz (Cardinal) on Jun 20, 2011 at 10:03 UTC
    The source code is a test file like any other, and can be edited.

    But since perl first compiles a script before it runs the mainline code, changes in the source script don't change the runtime behavior, unless you force it to (for example with exec).

    But maybe you are trying to solve an XY Problem - what do you want to achieve in the end? Maybe there's a better (simpler, more robust) way?

Re: changing source code in run time
by dHarry (Abbot) on Jun 20, 2011 at 11:31 UTC

    You can use the eval function to run perl code on-the-fly. I mean, supply some perl code to a running script, and from that script run the supplied code with the eval function. Whether or not that's a good idea is another matter. But is does sound a bit like a X-Y problem. Why do you think you need this feature, e.g. what are you trying to achieve?



      I've used what Harry noted here to pull code from a Database and later a version control system. I built it so that if the eval fails it will try the next older version. This way the developers don't ever need access to the production servers and they have to load the code into version control to get it into production. Plus I built some nice "Change Management" around it. :)


      Learn patience, you must.
      Young PerlMonk, craves Not these things.
      Use the source Luke.
Re: changing source code in run time
by ikegami (Pope) on Jun 20, 2011 at 18:38 UTC
    What are you trying to do?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://910542]
Approved by moritz
Discipulus sometimes i'm here alone with you, bony brother
[Discipulus]: ok a Perl one: how approach the task of getting all distinct paths from the edge to a node of a pascal triangle (nobackwards)?
[Discipulus]: each node has 2 descendants only: can i just compose hash keys usinng coords?
[karlgoethebier]: Discipulus: you shouldn't smoke turkish spices before noon
[Discipulus]: karl you says the same of my mom: in your place I'd been
[Discipulus]: preoccupied.. ;=)
Discipulus stopped with turkisk spices anyway.. but better hashes than arrays!

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (12)
As of 2018-03-19 10:55 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (239 votes). Check out past polls.