NAME
Tie::Cfg - Ties simple configuration files to hashes.
SYNOPSIS
use Tie::Cfg;
### Sample 1
tie my %conf, 'Tie::Cfg',
READ => "/etc/connect.cfg",
WRITE => "/etc/connect.cfg",
MODE => 0600,
LOCK => 1;
$conf{test}="this is a test";
untie %conf;
### Sample 2
my $limit="10000k";
tie my %files, 'Tie::Cfg',
READ => "find $dirs -xdev -type f -size +$limit -printf \"%h/%f:%k\\n\" |";
if (exists $files{"/etc/passwd"}) {
print "You've got a /etc/passwd file!\n";
}
while (($file,$size) = each %newdb) {
print "Wow! Another file bigger than $limit ($size)\n";
}
untie %files;
### Reading and writing an INI file
tie my %ini, 'Tie::Cfg', READ => "config.ini", WRITE => "config.ini", INIMODE => 1;
my $counter=$ini{"section1.counter1"};
$counter+=1;
$ini{"section1.counter1"}=$counter;
untie %ini;
### Reading an INI file with user separator
tie my %ini, 'Tie::Cfg', READ => "config.ini", INIMODE => 1, SEP => "\t\t", SPLITSEP => "\s+";
my $counter=$ini{"section1.counter1"};
$counter+=1;
$ini{"section1.counter1"}=$counter;
untie %ini;
DESCRIPTION
This module reads in a configuration file at 'tie' and writes it at 'untie'.
You can use file locking to prevent others from accessing the configuration file, but this should only be used if the configuration file is used as a small data file to hold a few entries that can be concurrently accessed. Note! In this case a persistent ".lock" file will be created.
Mode is used to set access permissions; defaults to 0640. It's only set if a file should be written (i.e. using the WRITE keyword).
INIMODE lets you choose between Windows alike .ini configuration files and simple key[:=]value entried files.
Keys that end on [\[][0-9]+[\]] will be interpreted as arrays and will show up in the tied hash as an array element. For example:
[array-section]
var[0]=1
var[1]=2
var[2]=3
will show up in a tied %cfg hash like:
for (0..2) {
print $cfg{array-section.var}[$_],"\n";
}
PREREQUISITE
Perl's Version >= 5.6.0! Please don't test this module with anything earlier.
AUTHOR
Hans Oesterholt-Dijkema <hans@oesterholt-dijkema.emailt.nl>
BUGS
Probably.
LICENCE
Perl.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 335:
'=end' without a target?