Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Separating configuration data and script logic in Perl scripts

I find the following anti-pattern repeated in my Perl scripts: the script contains some machine/setup specific settings which I store in-line as constants in the script whereas the rest of the script is general in nature:

#!/usr/bin/perl

use strict;
use warnings;

# machine specific settings at the start of the script.
my $SETTING_1 = "foo";
my @SETTING_2 = ("123", "456");
my $SETTING_3 = "something";

# general part of script follows.
...

This pattern is somewhat okay when running on one machine, but as soon as I want to distribute the script to multiple machines the trouble starts since I must keep track so that I do not overwrite the settings part with new updates in the general part.

The correct solution is obviously to have one general script file and have it read a configuration file which is specific to the environment that the script runs in.

My question is: What CPAN module would you recommend for solving this problem? Why?

like image 717
knorv Avatar asked Mar 04 '10 17:03

knorv


1 Answers

For configuration files, I like to use YAML. Simple, cross-platform, human-readable, and no danger of your configuration accidentally morphing into an actual program.

like image 91
friedo Avatar answered Sep 29 '22 10:09

friedo