View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Jos Boumans > Config-Auto-0.20 > Config::Auto



Annotate this POD (1)


New  6
Open  1
View/Report Bugs
Module Version: 0.20   Source   Latest Release: Config-Auto-0.44


Config::Auto - Magical config file parser


  use Config::Auto;

  # Not very magical at all.
  my $config = Config::Auto::parse("myprogram.conf", format => "colon");

  # Considerably more magical.
  my $config = Config::Auto::parse("myprogram.conf");

  # Highly magical.
  my $config = Config::Auto::parse();


This module was written after having to write Yet Another Config File Parser for some variety of colon-separated config. I decided "never again".

When you call Config::Auto::parse with no arguments, we first look at $0 to determine the program's name. Let's assume that's snerk. We look for the following files:


Additional search paths can be specified with the paths option.

We take the first one we find, and examine it to determine what format it's in. The algorithm used is a heuristic "which is a fancy way of saying that it doesn't work." (Mark Dominus.) We know about colon separated, space separated, equals separated, XML, Perl code, Windows INI, BIND9 and irssi style config files. If it chooses the wrong one, you can force it with the format option.

If you don't want it ever to detect and execute config files which are made up of Perl code, set $Config::Auto::DisablePerl = 1.

When using the perl format, your configuration file will be eval'd. This will cause taint errors. To avoid these warnings, set $Config::Auto::Untaint = 1.

When using the perl format, your configuration file will be eval'd using do(file). This will cause taint errors if the filename is not untainted. To avoid these warnings, set $Config::Auto::Untaint = 1. This setting will not untaint the data in your configuration file and should only be used if you trust the source of the filename.

Then the file is parsed and a data structure is returned. Since we're working magic, we have to do the best we can under the circumstances - "You rush a miracle man, you get rotten miracles." (Miracle Max) So there are no guarantees about the structure that's returned. If you have a fairly regular config file format, you'll get a regular data structure back. If your config file is confusing, so will the return structure be. Isn't life tragic?

Here's what we make of some common Unix config files:


    $VAR1 = {
          'nameserver' => [ '', '', '' ],
          'search' => [ '', '' ]


    $VAR1 = {
          'root' => [ 'x', '0', '0', 'root', '/root', '/bin/bash' ],


    $VAR1 = {
          'append' => '""',
          'responsiveness' => '',
          'device' => '/dev/psaux',
          'type' => 'ps2',
          'repeat_type' => 'ms3'


    $VAR1 = {
          'netgroup' => 'nis',
          'passwd' => 'compat',
          'hosts' => [ 'files', 'dns' ],


Although Config::Auto is at its most magical when called with no parameters, its behavior can be reined in by use of one or two arguments.

If a filename is passed as the first argument to parse, the same paths are checked, but Config::Auto will look for a file with the passed name instead of the $0-based names.

 use Config::Auto;

 my $config = Config::Auto::parse("obscure.conf");

The above call will cause Config::Auto to look for:


Parameters after the first are named.


forces Config::Auto to interpret the contents of the configuration file in the given format without trying to guess.


add additional directories to the search paths. The current directory is searched first, then the paths specified with the path parameter. path can either be a scalar or a reference to an array of paths to check.


Config::Auto recognizes the following formats:


When using a Perl config file, the configuration is borked

Give Config::Auto more hints (e.g., add #!/usr/bin/perl to beginning of file) or indicate the format in the parse() command.


BIND9 and irssi file format parsers currently don't exist. It would be good to add support for mutt and vim style set-based RCs.


Please report bugs or other issues to <>.


This module by Jos Boumans <>.


This library is free software; you may redistribute and/or modify it under the same terms as Perl itself.

syntax highlighting: