Listing 1 Create a configuration file from a template
use Date::Calc qw(:all);
# Substitutes Analog Paramters in an input Configuration Template and
# saves the new config file to disk.
sub createAnalogConfigFile {
my ($in_filename, $out_filename, $config_substitutes) = @_[0..2];
my $analog_config;
# Load in the template config file into a string
open INFILE, $$in_filename or die "Cant open $$in_filename\n";
while (<INFILE>) { $analog_config .= $_ }
close INFILE;
# Substitute all parameters that are in the Hash
for my $key (keys %$config_substitutes) {
$analog_config =~ s/$key\s* \s*.*/$key $$config_substitutes{$key}/g;
}
# Output the new config file
open OUTFILE, ">$$out_filename" or die "Cant open config file $$out_filename\n";
print OUTFILE $analog_config;
close OUTFILE;
}
|