Home Up Mail an Joachim Pimiskern Impressum


IniParser is a Perl module for reading Microsoft Windows style .ini files. Files with the extension .ini are text files for storing the configuration or settings of other programs.

Status: Freeware; modify and use it at your own risk. I'd be glad if you left a comment in the source file about the original author, Joachim Pimiskern.



Simply use IniParser;
You may know that you can add include paths to Perl with the -I command line parameter.


Suppose we have c:\test.ini with the following content.

;--- This is the directories section ---
Input=c:\autoexec.bat     ; Input directory
Output = c:\autoexec.bak  ; Output directory

[Another Section]
AnyVariable = 3.1415

This is a Perl program that makes use of IniParser.

use IniParser;
my $ini = IniParser->new("c:\\test.ini");
my $inputdir    = $ini->expectEntry("Directories","Input");
my $outputdir   = $ini->expectEntry("Directories","Output");
my $AnyVariable = $ini->expectEntry("Another Section","AnyVariable");
print "Input  Directory = <$inputdir>\n";
print "Output Directory = <$outputdir>\n";
print "AnyVariable      = <$AnyVariable>\n";

The output then will be
Input  Directory = <c:\autoexec.bat>
Output Directory = <c:\autoexec.bak>
AnyVariable      = <3.1415>

Home Up Mail an Joachim Pimiskern Impressum