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 kind of a database 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 can be written (i.e. using the WRITE keyword).

AUTHOR

Hans Oesterholt-Dijkema <hans@oesterholt-dijkema.emailt.nl>

BUGS

Possibly.

LICENCE

Perl.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 284:

'=end' without a target?