sub ReadIniFile { my ($iniFile) = @_; my %config = (); local ($/) = undef; unless (open (INI, $iniFile)){ print (LOG "Error: couldn't read from INI $iniFile: $!\n"); die ("Error: couldn't read from INI $iniFile: $!\n"); } my $ini = ; close (INI); my (@mainpoints) = ($ini =~ /(\[\w+?\])\n/g); # extract [.....] my ($x, @contents) = split(/\[\w+?\]/, $ini); @config{@mainpoints} = @contents; foreach (keys %config){ my %subHash = (); my @values = split(/\n+/, $config{$_}); foreach (@values){ my ($key, $val) = split(/\s*\:\s*/, $_, 2); next unless defined $key; next if $key eq ''; next if $key =~ /^\s*\#/; $subHash{lc($key)} = $val; } $config{$_} = \%subHash; } return (\%config); } # ReadIniFile