punkish has asked for the wisdom of the Perl Monks concerning the following question:
# in my.conf file FOO 'this' # in my script use strict; use Config::Simple; use vars qw($FOO); Config::Simple->import_from("my.conf"); # the following works fine print "$FOO\n";
Now I want to add multiple values to FOO, so
# in my.conf file FOO 'this', 'that' # in my script use strict; use Config::Simple; use vars qw(@FOO); Config::Simple->import_from("my.conf"); # the following prints nothing at all for (@FOO) { print "$_\n"; } # however use vars qw($FOO); Config::Simple->import_from("my.conf"); # the following works fine for (@$FOO) { print "$_\n"; } # however, if I provide only one value for FOO in my.conf # in my.conf file FOO 'this' # the following croaks for (@$FOO) { print "$_\n"; } Can't use string ("this") as an ARRAY ref while "strict refs" in use at ./test.pl line 41, <FH> line 1.
Well, I don't want it to croak just in case the user provided only a single value for FOO, however, I have no way of knowing before-hand if one or multiple values for FOO will be provided.
Now, more complications -- FOO is the generic container to hold values with which I have to do something. Except, FOO should be able to hold different kinds of values. For example, FOO holds values that should be inserted in a db. Except, some values in FOO should be inserted in col A while others should be inserted in col B. Yes, instead of FOO, I could have TO_INSERT_IN_A and TO_INSERT_IN_B, however, that wouldn't be extensible to arbitrary columns.I really want to be able to specify perhaps an AoA or HoA in my config file. How?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Simpler Config-Simple needed
by Roy Johnson (Monsignor) on Oct 25, 2005 at 18:16 UTC | |
|
Re: Simpler Config-Simple needed
by xdg (Monsignor) on Oct 25, 2005 at 18:21 UTC | |
by perrin (Chancellor) on Oct 25, 2005 at 19:37 UTC | |
|
Re: Simpler Config-Simple needed
by jbware (Chaplain) on Oct 25, 2005 at 18:20 UTC |