This will replace itPROD_RT = $(RUNTIME) # other variant PROD_RT = ~/prod/$(ENVIRONMENT)/$(VERSION)/bin PLAN_ID = $(DATABASE)
Use a dialog to collect the options for the Environment (Database, Test or Production etc) give the collected variables requested files into the Routine and generate the configuration files. Then use the selected environment.#!perl.exe -w replace for real OSs use strict; use warnings; my $debug = 1; sub get_value # used in substitution { my ($ref_values, $key) = @_; print " look for $key ?\n" if $debug; my $result = ( exists $ref_values->{$key} ) # if exists ... ? $ref_values->{$key} # return Value : "*ERR*" # else return *ERR* } sub generate_file { my ($templ_file, $ref_inivars, $target_file) = @_; open IN, "<$templ_file" or return -1; open OUT, ">$target_file" or return -2; while ( my $line = <IN> ) { $line=~s/\$\((\w+)\)/&get_value($ref_inivars,$1)/ge; print OUT $line; } return 0; } #------------------ # Use the Code generate_file ( "./template/inifile.ini", { %ENV, # just to demonstrate 'RUNTIME' => "~/prod/test/v1.2/bin", 'VERSION' => "v1.2", 'ENVIRONMENT' => "test" 'DATABASE' => "L63DTST", }, "result.ini" );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: Generate Configuration files
by merlyn (Sage) on Aug 27, 2002 at 17:27 UTC | |
by Brutha (Friar) on Aug 28, 2002 at 09:33 UTC | |
by blazar (Canon) on Jul 08, 2007 at 09:35 UTC |