The typical method used to accept configuration details is to define the variables at the beginning of the script and let users modify them if they want to. But, remember the config files for old DOS programs or the .ini iles under Windows ? If you would like to give your users the flexibility of modifying configuration variables in that way, you could use the subroutine given below :
sub parse_config_file {
local ($config_line, $Name, $Value, $Config);
($File, $Config) = @_;
if (!open (CONFIG, "$File")) {
print "ERROR: Config file not found : $File";
exit(0);
}
while (
|
This reads the config file mentioned ($path_and_filename) and populates the hash (%Config) with the name value pairs found in the config file.
Blank lines and lines starting with # in the config file are ignored.
If the config file was :
# Description of option1 option1 = value1 # Description of option2 option2 = value2 |
The hash would be :
Config{option1} = value1
Config{option2} = value2
|