in reply to one script, not twelve nearly identical ones!

It sounds like what you're looking for is a templating system; a template is a way to describe how your output looks outside the code of the program. By changing the template, you can adapt the output for any other situation. Personally, I'm a big fan for Template Toolkit, which is generally considered the most powerful and complete one as well, but there are many others with merit as well. See perrin's templating system comparison.

That covers the output side. If the format of your input XML file also differs from application to application, things get trickier. If the differences are trivial enough, it will probably suffice to stick some description into a configuration file; for a script processing an XML file, such a configuration might list XPath expressions, f.ex.

If your needs vary wildly from case to case, you should instead pull common functionality out of the program, collect it in a module, and use that module in your various scripts.

Makeshifts last the longest.

  • Comment on Re: one script, not twelve nearly identical ones!