configDB.pm: improve reading of config file

git-svn-id: https://svn.fhem.de/fhem/trunk@11738 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
betateilchen 2016-07-04 20:02:31 +00:00
parent 36974a2872
commit 4fe30a7f0c

View File

@ -116,6 +116,8 @@
# #
# 2016-07-03 - added support for multiple hosts (experimental) # 2016-07-03 - added support for multiple hosts (experimental)
# #
# 2016-07-04 - fixed improve config file read
#
############################################################################## ##############################################################################
# #
@ -179,8 +181,16 @@ if(!open(CONFIG, 'configDB.conf')) {
Log3('configDB', 1, 'Cannot open database configuration file configDB.conf'); Log3('configDB', 1, 'Cannot open database configuration file configDB.conf');
return 0; return 0;
} }
my @config=<CONFIG>; #my @config=<CONFIG>;
close(CONFIG); #close(CONFIG);
my @config;
while (<CONFIG>){
my $line = $_;
$line =~ s/^\s+|\s+$//g;
push (@config,$line) if($line !~ m/^#/ && length($line) > 0);
}
close CONFIG;
use vars qw(%configDB); use vars qw(%configDB);
@ -197,9 +207,11 @@ my $count = @configs;
if ($count > 1) { if ($count > 1) {
my $fhemhost = hostname; my $fhemhost = hostname;
foreach my $c (@configs) { foreach my $c (@configs) {
next unless $c =~ m/^%dbconfig.*/;
eval $c; eval $c;
last if ($dbconfig{fhemhost} eq $fhemhost); last if ($dbconfig{fhemhost} eq $fhemhost);
} }
eval $configs[0] unless (defined($dbconfig{fhemhost}) && length($dbconfig{fhemhost}))
} else { } else {
eval $configs[0]; eval $configs[0];
} }