Read from config file and use it in perl program

Hi,

I want to configure some values in config file like below

 
work_dir /home/work 
csv_dir /home/csv 
sql_dir /home/sqls 
reportfirst yes

and i want to store each value in variable to use it further in my my perl program ??

any thought on this(i am new to perl) ?

Thanks,
Raghavendra

This is what I am already using in my programs

config file:

# comments are allowed 
work_dir = /home/work
csv_dir = /home/csv 
sql_dir = /home/sqls 
reportfirst = yes

In script:

my %configParamHash = ();
open ( _FH, $configFileName ) or die "Unable to open config file: $!";
 
while ( <_FH> ) {
    chomp;
    s/#.*//;                # ignore comments
    s/^\s+//;               # trim leading spaces if any
    s/\s+$//;               # trim leading spaces if any
    next unless length;
    my ($_configParam, $_paramValue) = split(/\s*=\s*/, $_, 2);
    $configParamHash{$_configParam} = $_paramValue;
}
close _FH;

Now %configParamHash will contain the key-value pair of the config values.

e.g.

my $_csvDir = $configParamHash{csv_dir};

Have a look at Config::IniFiles as well.

Config::IniFiles - search.cpan.org