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

Do you think a settings hash needs to be tied to the file it's in? I mean, it only takes 1 line to save it: saveConfig();

I've already tyed %db to wpconfig.cgi BUT to use %db you have to do things like:

$db{userdata}->{L0rdPhi1->{password} and $db{config}->{key}

vs (no tying):

$userdata{L0rdPhi1}->{password} and $config{key}

So, which is better... the long hash (saves by it's self) or the shorter hash (doesn't save by it's self--have to do a saveConfig() everything you change something).

Replies are listed 'Best First'.
Re: Hashes: long or short?
by tadman (Prior) on May 27, 2002 at 22:11 UTC
    If you're just plain Lazy, you can do something like this:
    my %db; tie(%db, 'NDBM_File', ...); my $userdata = \%{$db{userdata}}; my $config = \%{$db{config}}; if ($userdata->{foo} && $config->{key}) { # ... }
    Using aliases to deep points in your data structure can be a good way to shorten your code. I find that when working "deep", I try and use a pointer as a starting point that is as close as is practical to the final values.
Re: Hashes: long or short?
by Zaxo (Archbishop) on May 27, 2002 at 21:13 UTC

    Is your config file supposed to keep a persistent state? If so, you probably shouldn't allow forks, threads, or concurrent instances of the program.

    If the need is for a stable and valid startup state, then you should restrict how the file is written.

    After Compline,
    Zaxo