***** infoCopter.com/perl *****
CPAN Config::IniFilesConfig::IniFiles - A module for reading .ini-style configuration files.#!/usr/bin/perl -w
use Config::IniFiles;
my $cfg = Config::IniFiles->new( -file => 'configini.ini' );
my $log_suffix = $cfg->val('log', 'suffix');
my $foo_foo = $cfg->val('foo', 'foo');
print "[log] suffix = \"$log_suffix\"\n";
print "[foo] foo = \"$foo_foo\"\n";
Input Config FileBoth the hash mark (#) and the semicolon (;) are comment characters. $ cat configini.ini[log] suffix = .log [foo] foo = bar Output$ ./configini.pl[log] suffix = ".log" [foo] foo = "bar" TipsGet all sections from you ini file my @all_sections = $cfg->Sections();
foreach (@all_sections) {
print "$_\n";
}
Or shorterforeach (sort $cfg->Sections) {
print "$_\n";
}
Fill all keys from a section into an arraymy @values = $cfg->Parameters('yourSection');
Loop sorted through all sections plus print its parameters and valuesforeach my $section (sort $cfg->Sections) {
next unless $section =~ /^test_\d+/;
print "$section:\n";
my @values = $cfg->Parameters($section);
foreach (@values) {
print "--> $_ = ", $cfg->val($section, $_), "\n";
}
}
Related Links
|