|
PTools::SDF::INI - Implements a Simple Data File in "Windows INI" format |
PTools::SDF::INI - Implements a Simple Data File in ``Windows INI'' format
This document describes version 0.08, released Feb 15, 2003.
use PTools::SDF::INI;
$iniObj = new PTools::SDF::INI( $fileName );
or $iniObj = new PTools::SDF::INI( $fileName, $iniSection, @fields );
$fieldNames = $iniObj->param($sectName); # "name1:name2:name3"
(@fieldNames) = $iniObj->param($sectName); # array of field names
$fieldValue = $iniObj->param($sectName, $fieldName);
$iniObj->param($sectName, $fieldName, $newValue);
$sectionCount = $iniObj->param; # number of "sections"
(@sectionNames) = $iniObj->param; # name of each section
The following is roughly equivalent to the dump method used to display the contents of objects of this class.
foreach my $secName ( $iniObj->param ) {
print "$secName\n";
foreach my $fieldName ( $iniObj->param( $secName ) ) {
my($fieldValue) = $iniObj->param($secName, $fieldName);
print " $fieldName = $fieldValue\n";
}
}
The PTools::SDF::INI class reads and writes files in the MS Windows '.INI' format.
[personalData]
first = field value
last = other field value
telnet = another field value
Warning: I never found any documentation regarding this file format. If you can point me to official MicroSoft documentation on this format, I would appreciate it. Thanks in advance.
This class is often used simply to store data in memory during the execution of a script. It is often convenient to use familiar data structures, such as this file format, without any actual disk file.
Note that when a ``subset'' of a data file is loaded, the save method is disabled. Use the Force parameter of the save method to override, or use the ctrl method to specify a different FileName prior to calling save.
Examples
$iniObj = new PTools::SDF::INI;
$iniObj = new PTools::SDF::INI( "/application_dir/data/testfile.ini" );
Examples:
$fieldValue = $iniObj->param( 'SectionOne', 'FieldOne' );
$iniObj->param( 'SectionOne', 'FieldOne', "New Value" );
Examples:
# Specify a new file name for the current PTools::SDF::INI object
$fieldValue = $iniObj->ctrl( "fileName", '/tmp/newDataFilename' );
# Fetch a colon-separated list of field names in the file. # In list context, an array of field names is returned.
$fieldList = $iniObj->ctrl( "dataFields" ); (@fieldList) = $iniObj->ctrl( "dataFields" );
# Specify a new list of fieldnames for the current object # WARN: this will *not* change any existing field names, and # only existing fields that appear in this list will be written # to the data file via the "save" method. This is provided as # a way to create a subset of a file, to add new fields, and/or # to re-arrange the field order when file is saved to disk.
$iniObj->ctrl( "dataFields", "colon:separated:list:of:names" ); $iniObj->ctrl( "dataFields", @fieldNameList );
Example:
# Loading a subset of a data file sets an attribute to disable the # "save" method. This removes the attribute and re-enables "save":
$iniObj->ctrlDelete('readOnly');
Examples:
$value = $iniObj->delete( "SectionOne", "FieldTwo" );
Note: Only those SectionNames that have an entry in the dataFields control parameter will be written to the disk file. See the ctrl method, above, for details on using this attribute.
Note that no control parameters are saved with the file.
Example:
$webUserid = $ENV{'REMOTE_USER'}; # (from Web Server Basic Auth)
$iniObj->save( $webUserid, $filename );
WARN: This will cause any records omitted during the load to be lost.
Examples:
$iniObj->save;
($stat,$err) = $iniObj->save;
$iniObj->save( undef, "newfilename" );
Another Example:
$iniObj->ctrl('fileName', "newfilename" );
$iniObj->save;
($stat,$err) = $iniObj->status;
$stat and die $err
if ( $iniObj->isLocked ) do { . . . }
if ( $iniObj->notLocked ) do { . . . }
($stat,$err) = $iniObj->status;
$stat = $iniObj->stat; # scalar context returns status number ($err)= $iniObj->stat; # array context returns error message
$err = $iniObj->err;
Examples:
print $iniObj->dump; # can produce a *lot* of output
This PTools::SDF::INI class inherits from the PTools::SDF::File abstract base class. Additional methods are available via this parent class.
See the PTools::SDF::Overview manpage, the PTools::SDF::ARRAY manpage, the PTools::SDF::CSV manpage, the PTools::SDF::DB manpage, the PTools::SDF::DIR manpage, the PTools::SDF::DSET manpage, the PTools::SDF::File manpage, the PTools::SDF::IDX manpage, the PTools::SDF::SDF manpage, the PTools::SDF::TAG manpage, the PTools::SDF::Lock::Advisory manpage, the PTools::SDF::Sort::Bubble manpage, the PTools::SDF::Sort::Quick manpage and the PTools::SDF::Sort::Shell manpage.
Chris Cobb, <nospamplease@ccobb.net>
Copyright (c) 1997-2007 by Chris Cobb. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|
PTools::SDF::INI - Implements a Simple Data File in "Windows INI" format |