I'd parse it in the following way... (haven't tested)
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 = <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
Best regards,
perl -e "$_=*F=>y~\*martinF~stronat~=>s~[^\w]~~g=>chop,print"