in reply to Config files

Your question is impossible to answer without knowing what you use to read in your config file. However, I suspect the module you use is "dumb" and won't do what you want it to do. It's up to the program to do it.
# Use the appropriate syntax for your module: my $root = ... my $code = ... my $include = ... my $lib = ... foreach ($code, $include, $lib) { s/%ROOT%/$root/gi; # -or- # # $code =~ s/%([A-Z][A-Z_]*)%/ # if ($1 eq 'ROOT') { # $root # } elsif (exists($ENV{$1})) { # $ENV{$1} # } else { # $1 # } # /eg }

Replies are listed 'Best First'.
Re^2: Config files
by sparkel (Acolyte) on Dec 07, 2004 at 00:09 UTC
    Basically I want to create a config file where the variables can be changed by people who don't know perl.

    So I was wondering...what is the best way to create the config file in terms of substituting variables that will be used over and over again in the config file.

    I just gave the example of the $root . '\code' , but is there a better way to subsititute the root variable in the config file?

    Thanks.

      If you're so concerned about the complexity the config file, why don't you write an interactive configuration utility?

      Back to the matter immedately at hand...

      You keep talking about the config file, while you should be talking about the module that reads the config file and the program that uses the module. If you used the code I posted earlier in this thread, you could write your config file as:

      [path] root = C:\test code = %root%\code1 include = %root%\include lib = %root%\lib

      instead of

      [path] root = C:\test code = C:\test\code1 include = C:\test\include lib = C:\test\lib

      It doesn't get any simpler (from the config file's perspective). What else do you want?