What sort of data structure do you want to store the config file in? This (untested) code builds a hash of arrays. The keys to the hash are the section names and the values are an array of the values within that section.
my %config; my $section; open(CONF, 'config.ini') || die "Can't open conf.ini: $!\n"; while (<CONF>) { next unless /\S/; chomp; if (/\[(.+)\])/) { $section = $1; } else { push @{$config{$section}}, $_; } }
Update: Bug corrected. Thanks to jeroenes for pointing it out.
As for fundflow's comment. He has a good point. My solution would probably to read the first line separately and if it wasn't a 'section' line to die with an error.
--
"Perl makes the fun jobs fun
and the boring jobs bearable" - me
In reply to Re: CPAN, why hast thou forsaken me?
by davorg
in thread CPAN, why hast thou forsaken me?
by myocom
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |