in reply to Config file default options?

First, I think I would store the config file data in a hash, rather than an array. That way you can look up a particular datum more easily, by its name.

As for the code that reads the config file, there are modules on the CPAN for reading config files, see for instance here, although some of those may require the config file to be in a certain format that may not match yours. (On the other hand, if you don't have to accommodate pre-existing config files, you could just define your config file format to be the format that the module reads.)

Now, the other thing you asked about is checking the config data for each of several values and, if they are not present, calling a routine to construct them. If I were doing that, the first thing I'd do is make a list of the values I want (e.g., From, To, Cc, and so forth). The second thing I'd do is make the list a hash, with the name of the header being the key, and the subroutine that constructs the header would be the value. Something along these lines...

my %dispatch = ( From => sub { return '"Nobody" <nobody@localhost>'; }, Subject => sub { die "The GNKSA requires that the subject field alwa +ys be specified by the user."; }, # and so forth. );

The third thing would be to actually do the assignments, and I'd probably use a foreach loop over the keys for that part. Something like this...

for my $k (keys %dispatch) { if (exists $config{$k}) { $value{$k} = $config{$k}; } else { $value{$k} = $dispatch{$k}->(); } }

It is possible to golf that loop down to one line, but you either lose the exists test (resulting in a situation where a user cannot specify a false value) or else have to use the ? : operator, which I find beginners often don't like. Anyway, the dispatch table is going to be most of the work.


Sanity? Oh, yeah, I've got all kinds of sanity. In fact, I've developed whole new kinds of sanity. Why, I've got so much sanity it's driving me crazy.