Chapter 10. Configuring Perl Programs

It seems that whenever I write what I think is a useless or short-term program, then show it to someone, I ultimately end up supporting a new application. People ask me to write a similar program for them or slightly modify a program for them. The change never seems to actually be slight, either.

I don’t get trapped into creating or maintaining multiple versions of a program. I can make the programs configurable, and do it so users don’t have to touch the code. Otherwise they are going to modify the code themselves and come back to me when they don’t know how to fix the syntax error from the semicolon they forgot. A little work making my program configurable saves me headaches later.

Things Not to Do

The easiest, and worst, way to configure my Perl program is simply to put a bunch of variables in it and tell people to change those values if they need different settings. The user then has to open my program and change the values to change the behavior of my program. This gives people the confidence to change other things too, despite my warning to not change anything past the configuration section. Even if those users stay within the section where I intend them to edit code, they might make a syntax error. That is, they will make syntax errors. Not only that, if they have to install this program on several machines, they’ll end up with different versions on each machine. Any change or update in the program requires them to edit every version: ...

Get Mastering Perl, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.