in reply to Persistence for options?

Why not tie your option hash to a DB_File ?
use DB_File; tie %hash, "DB_File", $filename or die "NO DIE\n"; %hash{key}='value'; untie %hash;
This should create a file $filename and stores all the hash inside. When your program is ended this file will survive and will again be read by the next start of your program.
----------------------------------- --the good, the bad and the physi-- -----------------------------------

Replies are listed 'Best First'.
Re: Re: Persistence for options?
by Corion (Patriarch) on Aug 15, 2001 at 20:10 UTC

    Binary config files are evil. Somebody with more experience told me that even Unix used once binary config files (like, for example, sendmail still seems to do and the mailman program (written in Python) does), and it opens a whole can of worms, like version dependencies, platform dependencies and general unmodifiability of the config file if the program used to create it dosen't start anymore.

    Just imagine a version of Perl linked to another (version of) Berkeley DB, or that you want to transfer your config files between machines with different endianness, or between Windows and Unix, where all the path names change.

    Or imagine the hell if the program crashes while writing the configuration file, and won't start up anymore, because the config file is broken, and you have no easy way to tell if the file is complete, and no easy way to fix/salvage the current configuration or what's left of it...

      If you don't trust binary files then maybe a better way will be, to use DBI and CSV like that:
      tie %line, 'Tie::RDBM', "CSV:f_dir=/whatever/log", {table => 'anyfilen +ame', create => 1} or die "no tie $!\n";
      Then you get a human readable file, which is editable.
      ----------------------------------- --the good, the bad and the physi-- -----------------------------------