4

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.

pboin
  • 1,500

2 Answers2

2

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:

#!/usr/bin/m4

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

chmod +x file.m4
Mei
  • 1,136
1

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

tex
  • 189
  • 3