What is the best way to parse ini files in Perl?
the file is formated in this way:
[group1]
value1
value2
value3
[group2]
value1
value2
value3
value4
[group3]
value1
value2
See Question&Answers more detail:osWhat is the best way to parse ini files in Perl?
the file is formated in this way:
[group1]
value1
value2
value3
[group2]
value1
value2
value3
value4
[group3]
value1
value2
See Question&Answers more detail:osYou haven't told us the expected format for the data or shown any existing code, so it's impossible to know what you're looking for, but this should get you at least 90% of the way there:
use strict;
use warnings;
use Data::Dumper;
my %config;
my $group = '';
while (<DATA>) {
chomp;
next unless /S/;
if (/^[([^]]+)]/) {
$group = $1;
next;
}
push(@{$config{$group}}, $_);
}
print Dumper(\%config);
__DATA__
[group1]
value1
value2
value3
[group2]
value1
value2
value3
value4
[group3]
value1
value2