kdmurphy001 has asked for the wisdom of the Perl Monks concerning the following question:

Hi There Monks, Is there a way you can update a hard-coded variable? Looking for something along the lines of a run-time and previous run-time. I can go the run-time no problem but the only way I can think of to do the "previous" run-time, which would be displayed at the start of the script, would be to write it to a file and then pull from that file based on X criteria.

What I would rather do is have the previous run-time stored in the script and update it each time the script runs (or calculate an average). *Thanks for the tips guys. Wasn't sure if that was the "norm". I"ll go the database route. Thanks again!

Replies are listed 'Best First'.
Re: Updating hard coded variable?
by Anonymous Monk on Oct 06, 2009 at 11:46 UTC
Re: Updating hard coded variable?
by thunders (Priest) on Oct 06, 2009 at 13:53 UTC
    Your first approach(writing the data to a flat file or to a database or DBM) is a totally sane way to do this. Modifying the script itself in-place is trickier, and much more error prone.
Re: Updating hard coded variable?
by tweetiepooh (Hermit) on Oct 06, 2009 at 16:09 UTC
    There are ways to do (nearly) anything in Perl but self modifying code is "not a good idea". Is there a reason for not writing out to a persistent store (file/database)?

    You could wrap your script inside another script which would capture a return value and then pass that value into the script as a parameter on the next run but again that is a complex and odd way to accomplish what is better done with a data store.