Author image Noah Petherbridge


Config::INI::Simple - Simple reading and writing from an INI file--with preserved comments, too!


  # in your INI file
  ; The name of the server block to use
  ; Use one of the blocks below.
  server = Server01

  ; All server blocks need a host and port.
  ; These should be under each block.


  # in your Perl script
  use Config::INI::Simple;

  my $conf = new Config::INI::Simple;

  # Read the config file.
  $conf->read ("settings.ini");

  # Change the port from "Server02" block
  $conf->{Server02}->{port} = 2236;

  # Change the "server" to "Server02"
  $conf->{default}->{server} = 'Server02';

  # Write the changes.
  $conf->write ("settings.ini");


Config::INI::Simple is for very simplistic reading and writing of INI files. A new object must be created for each INI file (an object keeps all the data read in from an INI which is used on the write method to write to the INI). It also keeps all your comments and original order intact.


A basic INI format is:



Comments begin with either a ; or a # and must be on their own line. The object's hashref will contain the variables under their blocks. The default block is "default" (see new for defaults). So, $conf-{Block2}->{VAR2} = Value2>



Creates a new Config::INI::Simple object. You can pass in certain settings here:

__file__ - Sets the file path of the INI file to read. If this value is set, then read and write won't need the FILE parameter.

__default__ - Sets the name of the default block. Defaults to 'default'

__eol__ - Set the end-of-line characters for writing an INI file. Defaults to Win32's \n

__append__ - Set to true and new hash keys will be appended to the file upon writing. If a new block is added to the hashref, that block will be appended to the end of the file followed by its data. Defaults to 1.

read (FILE)

Read data from INI file FILE. The object's hashref will contain this INI file's contents.

write (FILE)

Writes to the INI file FILE, inputting all the hashref variables found in the object.


Resets the internal hashref of the INI reader object. The four settings specified with new will be reset to what they were when you created the object. All other data is removed from memory.


  Version 0.02
  - Uploaded a version of the module that's been modified by some
    other Perl hackers.

  Version 0.01
  - Initial release.


C. J. Kirsle <kirsle -at->


Copyright (C) 2006 by C. J. Kirsle

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.7 or, at your option, any later version of Perl 5 you may have available.