in reply to CPAN, why hast thou forsaken me?
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: CPAN, why hast thou forsaken me?
by myocom (Deacon) on Dec 21, 2000 at 03:52 UTC | |
|
Re: Re: CPAN, why hast thou forsaken me?
by fundflow (Chaplain) on Dec 20, 2000 at 22:38 UTC | |
|
Re: Re: CPAN, why hast thou forsaken me?
by jeroenes (Priest) on Dec 20, 2000 at 22:41 UTC |