I have a simple config file that I read in with Config::Simple. Now my config file wants to become less simple. Here is an example

# 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?

--

when small people start casting long shadows, it is time to go to bed

In reply to Simpler Config-Simple needed by punkish

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.