Author image Noah Petherbridge

NAME

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

SYNOPSIS

  # 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.
  [Server01]
  host=foo.bar.com
  port=7775

  [Server02]
  host=foobar.net
  port=2235

  # 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");

DESCRIPTION

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.

INI FILE FORMAT

A basic INI format is:

  [Block1]
  VAR1=Value1
  VAR2=Value2
  ...

  [Block2]
  VAR1=Value1
  VAR2=Value2
  ...

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>

METHODS

new

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.

reset

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.

CHANGES

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

  Version 0.01
  - Initial release.

AUTHOR

C. J. Kirsle <kirsle -at- cuvou.net>

COPYRIGHT AND LICENSE

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.