Options for handling a configuration file 
Author Message
 Options for handling a configuration file

I'm looking at various options for handling a configuration file and would
like some opinions.

My config file looks something like:

$base='/home/fred/html';
$logdir="$base/logs";
$reportdir="$base/logs";

etc

I have a CGI script to edit the configuration file.  At the moment, I'm just
doing something like:

require "config.pl";

print $query->textfield(-name=>'logdir',
                           -default=>$logdir);

The problem is that all of the variables that use $base will be expanded, so
to update the base location, requires updating *every* variable.

I was thinking that it would be better to ensure the variables don't expand,
ie:

$logdir will be displayed at $base/logs rather than /home/fred/html/logs

At this stage, I'm not keen to change the format of the configuration file,
but if that is my only option, then I'll do it.

Ideas?



Tue, 11 Nov 2003 08:34:53 GMT  
 Options for handling a configuration file

Quote:

> I'm looking at various options for handling a configuration file and would
> like some opinions.
> My config file looks something like:
> $base='/home/fred/html';
> $logdir="$base/logs";
> $reportdir="$base/logs";
> etc
> I have a CGI script to edit the configuration file.  At the moment, I'm just
> doing something like:
> require "config.pl";
> print $query->textfield(-name=>'logdir',
>                            -default=>$logdir);
> The problem is that all of the variables that use $base will be expanded, so
> to update the base location, requires updating *every* variable.
> I was thinking that it would be better to ensure the variables don't expand,
> ie:
> $logdir will be displayed at $base/logs rather than /home/fred/html/logs
> At this stage, I'm not keen to change the format of the configuration file,
> but if that is my only option, then I'll do it.

Don't require the file; open it as a plain text file and parse it (you
don't have to do a full Perl parse if all the lines are of the form
$variable="quoted string with possible interpolations"; just split on the
equal sign (being sure to use the three-argument form of split in order to
avoid problems with equal signs in the quoted strings) and use substr() or
the like to get the parameter names).

However, I'd be *very* wary of using a CGI script to edit a file
consisting of executable Perl code.  It's dangerous for the same reason
that placing the perl interpreter itself in your CGI directory is
dangerous; it allows anyone who can run the script to get your system to
run whatever Perl code they want.  Taint checking won't help here.



Tue, 11 Nov 2003 09:24:29 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Entry widget and -textvariable configuration option..

2. Taking a configuration option in a mega widget

3. Configuration file editor

4. No Configuration File (Sorry I asked : -)

5. Reading configuration files using strict

6. modifying configuration file settings

7. Splitting a configuration file into a hash

8. Verifying configuration files...

9. require user configuration files

10. perl newbie questions: database of complex configuration files

11. Hashes as configuration files, appending to @INC to find them

12. Newbie question : Read configuration file.

 

 
Powered by phpBB® Forum Software