in reply to User preference: To store params or not
globalConfig.cfguse strict; use warnings; use Getopt::Long; use Data::Dumper; my $log; my $account; my $href = {}; my $globalConfig = "globalConfig.cfg"; my $localConfig = "localConfig.cfg"; GetOptions ( "log=s" => \$log, "account=s" => \$account ); &getEnv($globalConfig); &getEnv($localConfig); print Dumper $href; exit; sub getEnv { # my $href = shift(@_); my $file = shift(@_); unless ( -e $file ) { print "Could not find $file \n"; exit(1); } open ( FILE , "< $file" ); while (<FILE> ) { chomp; next if $_ =~ /^\#/; my ($key, $variable) = split(/=/,$_,2); if ( $variable && $key ) { $variable =~ s/\s+//g; $key =~ s/\s+//g; $href->{config}->{$key} = $variable; } } close FILE; }
localConfig.cfg#comment log=global.log dir=c:\somepath
output#comment log=local.log account=C123454
$VAR1 = { 'config' => { 'account' => 'C123454', 'log' => 'local.log', 'dir' => 'c:\\somepath' } };
|
|---|