domm has asked for the wisdom of the Perl Monks concerning the following question:
A config file looks like:package Parent; require ('./parent.cfg'); package Parent::Child; @ISA=('Parent'); require ('./child.cfg'); package Parent::Child2; @ISA=('Parent'); require ('./child2.cfg'); package Parent::Child::Grandchild; @ISA=('Child'); require ('./grandchild.cfg');
$config={ string=>"bla", array=>['val1','val2'], hash=>{ foo=>'bar', }, # etc, put any valid perl data structure here };
My not-so-ideal solution: I wrote a routine (called "config") that returns config value associated with the given key. If the key is not found in %config of the calling package, the next upper package is searched, following @ISA.
This works quite OK, but it is sort of very inconvient to change values in arrays or hashes. If I want to override a part of list of some sort, I have to put the new complete list in the Child-Config.
Eg:
This results in a lot of very similar config entries.in parent.cfg #... list=>['val1','val2','val3'], in child.cfg #... list=>['val1','val2','val3','FOO','BAR'],
What I want:
I would like to do something like that:
the changes in child.cfg should only be visible in Parent::Child ,e.gparent.cfg: %config=( # complex data structur ) child.cfg: config_add('newval',$datastruct); config_remove('DontNeedThisHere'); config_push('array',$newval,$anotherval); # and some other data manipulation routines
Finally, my questions:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: OO Data Structures ?
by lachoy (Parson) on Dec 04, 2001 at 20:33 UTC | |
|
Re: OO Data Structures ?
by dragonchild (Archbishop) on Dec 04, 2001 at 20:57 UTC | |
|
Re: OO Data Structures ?
by miyagawa (Chaplain) on Dec 04, 2001 at 20:40 UTC | |
|
Re: OO Data Structures ?
by Fletch (Bishop) on Dec 04, 2001 at 21:22 UTC | |
|
(jeffa) Re: OO Data Structures ?
by jeffa (Bishop) on Dec 04, 2001 at 21:06 UTC | |
|
Re: OO Data Structures ?
by domm (Chaplain) on Dec 06, 2001 at 02:22 UTC |