|
PTools::SDF::TAG - Implements a Simple Data File in "Tagged Data" format |
PTools::SDF::TAG - Implements a Simple Data File in ``Tagged Data'' format
This document describes version 0.09, released Feb 15, 2003.
use PTools::SDF::TAG;
$tagObj = new PTools::SDF::TAG("$fileName");
Access and set data field values.
$dataValue = $tagObj->param("fieldName");
$tagObj->param("fieldName", "new value");
Access and set control field values.
$ctrlValue = $tagObj->ctrl("fieldName");
$ctrlValue = $tagObj->ctrl("ctrlField", "new value");
Determine the current field names contained in the $tagObj object.
$fields = $tagObj->ctrl("dataFields");
(@fields) = $tagObj->ctrl("dataFields");
$tagObj->ctrl("fileName", "data/control.tmp");
$tagObj->ctrl("dataFields","folder:seqnbr");
$tagObj->ctrl("fileName", "newFile");
$tagObj->save;
PTools::SDF::TAG is used to simplify data file access, and to eliminate dependance on field positions within files. This package reads and writes files in the following format.
[fieldName1]
some field value
[fieldName2]
other field with
a multiline value
[fieldName3]
another field value
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.
Examples
$tagObj = new PTools::SDF::TAG;
$tagObj = new PTools::SDF::TAG( "/home/cobb/data/testfile.tag" );
Examples:
$fieldCount = $ref->param;
$fieldValue = $ref->param($fieldName);
$ref->param($fieldName, $newValue);
Example:
# Delete the value for the 'proddesc' field
$tagObj->delete( 'proddesc');
Examples:
$ctrlFields = $tagObj->ctrl; # string of field names (@ctrlFields) = $tagObj->ctrl; # array of field names
$fieldValues = $tagObj->ctrl($fieldName); # string of values for field (@fieldValues) = $tagObj->ctrl($fieldName); # array of values for field
$tagObj->ctrl($fieldName, $newValue); $tagObj->ctrl($fieldName, @newValues);
Note that the 'version' and 'ctrlFields' values can NOT be changed using the ctrl method.
Example:
$tagObj->ctrlDelete('fileName');
use PTools::SDF::SDF; use PTools::SDF::TAG;
$sdfObj = new PTools::SDF::SDF; $tagObj = new PTools::SDF::TAG( "myFile.tag" );
$tagHashRef = $tagObj->tag2sdf;
$nextRecord = $sdfObj->count; # (one-based count)
$sdfObj->param( $nextRecord, $tagHashRef );
Note: Only those fields 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.
In addition, the only control parameters that are saved with the file are the field names.
Example:
$webUserid = $ENV{'REMOTE_USER'}; # (from Web Server Basic Auth)
$tagObj->save( $webUserid, $filename );
Examples:
$tagObj->save;
($stat,$err) = $tagObj->save;
$tagObj->save( undef, "newfilename" );
Another Example:
$tagObj->ctrl('fileName', "newfilename" );
$tagObj->save;
($stat,$err) = $tagObj->status;
($stat,$err) = $tagObj->status;
$stat = $tagObj->stat; # scalar context returns status number ($err)= $tagObj->stat; # array context returns error message
$err = $tagObj->err;
Example:
print $tagObj->dump;
This PTools::SDF::TAG 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::INI manpage, the PTools::SDF::SDF manpage, the PTools::SDF::Lock::Advisory manpage, the PTools::SDF::Lock::Selective manpage, the PTools::SDF::Sort::Bubble manpage, the PTools::SDF::Sort::Quick manpage and the PTools::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::TAG - Implements a Simple Data File in "Tagged Data" format |