I have been mulling over config files and their relationship to code for a while now and depending on the day and direction of the wind my opinions seem to change. More and mor
Recently I was working upon a project and I realised that I wanted to have conditionals inside my configuration file - which had previously just been a pretty simple one of the form:
key = val
key2 = val
name = `hostname`
I didn't want to write a mini-language, because unless I did it very carefully I couldn't allow the flexibility that would be useful.
Instead I decided that I'd have two forms:
If the file started with "#!" and was executable I'd parse the result of running it.
Otherwise I'd read it as-is
This means that I can now allow people to write "configuration files" that look like this:
#!/usr/bin/perl
if ( -x /bin/foo )
{
print <
This way I get the power of a dynamic configuration file if the user wants to use it, and the simplicity of not having to write my own mini-language.