I need to manage a growing set of similar-but-different ASCII files. ( It so happens that they're Apache VirtualHosts, but that's not particularly relevant. ) For each production website, the developers might want as many as four variant configs for a variety of reasons.

Would you please recommend your favorite templating system? I know of a few, M4 and Template::Toolkit come to mind. My most important feature isn't power, it's intuitive operation and elegant simplicity.

  • 1
    So I can't mention template toolkit? – xenoterracide Dec 10 '10 at 12:52
  • Of course, if you think that's the best way to go. I just want to make sure that I'm not missing something better. – pboin Dec 10 '10 at 13:10

I'm a big fan of using make and m4. I set up Nagios configuration files with extensive use of make and m4; Nagios is full of repetitive blocks that can be simplified through the use of m4.

The nice thing about make and m4 is that they are usually part of the base install or at least the base package repository on Linux and UNIX systems; with something like Template::Toolkit you'd have to install it. Perl is also heavier than m4 and make.

You can also, if you like, set up a semi-automated m4 run by putting this at the top of your m4 file (assuming the file is file.m4 for instance):

#!/usr/bin/m4 > file.conf

If you don't want to rewrite file.conf, then remove the redirection from the command:


You'd have to make the file.m4 file executable then as well:

chmod +x file.m4

I'd go for custom solution written in perl using e.g. Template::Toolkit. That way you can keep your code elegant and simple.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.