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

After messing around with AppConfig, I got things running quite well, regarding reading variables from a file into my script. Unfortunately though, I can't seem to find a way to store changes I might make to certain variables to the same configuration file (through AppConfig). What would be the best way to store these changes to the configuration file?

--
B10m

EDIT: Title modified

  • Comment on Saving changes to AppConfig configuration file

Replies are listed 'Best First'.
Re: Saving changes to AppConfig configuration file
by b10m (Vicar) on Nov 25, 2003 at 17:04 UTC
    After Googling, Super Searching and following this quiet thread, the "answer" struck me after some heavy drinking (who said alcohol was bad for the brain again? ;)

    My script checks whether there is a config file. If there's none, it will create one. The subroutine that creates it, used to have static, non-variable default values. So for example:
    open (CONF, ">$conffile"); print CONF<<EOF option1 = default text option2 = other text EOF ; close CONF;
    In stead of this approach, I now give the variables a default value during defining them:
    $config->define('option1', { DEFAULT => "default text" } ); $config->define('option1', { DEFAULT => "other text" } );
    Then, of course, I change the creation of the file to:
    open (CONF, ">$conffile"); print CONF "option1 = ", $config->option1(), "\n"; print CONF "option2 = ", $config->option2(), "\n"; close CONF;
    This way, I can change the variables through my Tk GUI and recreate the file (by calling the subroutine responsible):
    $config->option1('Specified through GUI'); &CreateConfigFile;
    It might not be the best solution, but it works rather simple and well. But since we're talking Perl here, there must be other solutions and I'd love to hear them :)

    --
    B10m