TeXLive::TLConfFile -- TeX Live generic configuration files


use TeXLive::TLConfFile;

my $conffile = TeXLive::TLConfFile->new($file_name, $comment_char,
                                        $separator, $type);
$conffile->value($key [, $value, ...]);


This module allows parsing, changing, saving of configuration files of a general style. It also supports three different paradigma with respect to multiple occurrences of keys: first-win specifies a configuration file where the first occurrence of a key specifies the value, last-win specifies that the last wins, and multiple that all keys are kept.

The configuration files (henceforth conffiles) can contain comments initiated by the $comment_char defined at instantiation time. Everything after a $comment_char, as well as empty lines, will be ignored.

The rest should consists of key/value pairs separated by the separator, defined as well at instantiation time.

Whitespace around the separator, and before and after key and value are allowed.

Comments can be on the same line as key/value pairs and are also preserved over changes.

Continuation lines (i.e., lines with last character being a backslash) are allowed after key/value pairs, but the key and the separator has to be on the same line.

Continuations are not possible in comments, so a terminal backslash in a comment will be ignored, and in fact not written out on save.


$conffile = TeXLive::TLConfFile->new($file_name, $comment_char, $separator [, $type])

instantiates a new TLConfFile and returns the object. The file specified by $file_name does not have to exist, it will be created at save time.

The $comment_char can actually be any regular expression, but embedding grouping is a bad idea as it will break parsing.

The $separator can also be any regular expression.

The $type, if present, has to be one of last-win (the default), first-win, or multiple.


Returns the location of the configuration file. Not changeable (at the moment).


Returns the comment character.


Returns the separator.


Returns the type.


Returns true (1) if the given key is present in the config file, otherwise returns false (0).


Returns the list of keys currently set in the config file.

$conffile->value($key [, $value, ...])

With one argument, returns the current setting of $key, or undefined if the key is not set. If the configuration file is of multiple type a list of keys ordered by occurrence in the file is returned.

With two (or more) arguments changes (or adds) the key/value pair to the config file and returns the new value. In case of first-win or last-win, the respective occurrence of the key is changed, and the others left intact. In this case only the first $value is used.

In case of multiple the $values are assigned to the keys in the order of occurrence in the file. If extra values are present, they are added. If on the contrary less values then already existing keys are passed, the remaining keys are deleted.

$conffile->rename_key($oldkey, $newkey)

Renames a key from $oldkey to $newkey. It does not automatically save the new config file.


Returns true (1) if some real change has happened in the configuration file, that is a value has been changed to something different, or a new setting has been added.

Note that changing a setting back to the original one will not reset the changed flag.


Saves the config file, preserving as much structure and comments of the original file as possible.


Reparses the configuration file.


For parsing a texmf.cnf file you can use

$tmfcnf = TeXLive::TLConfFile->new(".../texmf-dist/web2c", "[#%]", "=");

since the allowed comment characters for texmf.cnf files are # and %. After that you can query keys:

  $tmfcnf->value("trie_size", 900000);


This script and its documentation were written for the TeX Live distribution ( and both are licensed under the GNU General Public License Version 2 or later.