|
NAMEAsciiDB::TagFile - Tie class for a simple ASCII database SYNOPSIS # Bind the hash to the class
$tieObj = tie %hash, 'AsciiDB::TagFile',
DIRECTORY => $directory,
SUFIX => $sufix,
LOCK => $bool,
READONLY => $bool,
CACHESIZE => $cacheSize,
FILEMODE => $mode,
SCHEMA => {
ORDER => $arrayRef
KEY => {
ENCODE => $subRef,
DECODE => $subRef
}
};
# Save to disk all changed records
$tieObj->sync();
# Remove all records from memory (and save them if needed)
$tieObj->purge();
# Remove all records from memory (and save them if needed)
# iif there are more than $cacheSize records in memory
$tieObj->purge($cacheSize);
# Get all record keys
@array = keys %hash;
# Check if a record exists
exists $hash{$recordKey}
# Get a field
$scalar = $hash{$recordKey}{$fieldName};
# Assign to a field
$hash{$recordKey}{$fieldName} = $value;
DESCRIPTIONThe AsciiDB::TagFile provides a hash-table-like interface to a simple ASCII database. The ASCII database stores each record in into a file: $directory/recordKey1$sufix
$directory/recordKey2$sufix
...
$directory/recordKeyI<N>$sufix
And a record has this format: [fieldName1]: value1
[fieldName2]: value2
...
[fieldNameI<N>]: value2
After you've tied the hash you can access this database as access a hash of hashes: $hash{recordKey1}{fieldName1} = ...
To bind the %hash to the class AsciiDB::TagFile you have to use the tie function: tie %hash, 'AsciiDB::TagFile', PARAM1 => $param1, ...; The parameters are:
The data will be saved to disk when the hash is destroyed (and garbage collected by perl), so if you need for safety to write the updated data you can call the sync method to do it. EXAMPLES $dbObj = tie %tietag, 'AsciiDB::TagFile',
DIRECTORY => 'data',
SUFIX => '.tfr',
FILEMODE => 0644,
SCHEMA => { ORDER => ['name', 'address'] };
$tietag{'jose'}{'name'} = 'Jose A. Rodriguez';
$tietag{'jose'}{'address'} = 'Granollers, Barcelona, SPAIN';
$tietag{'cindy'}{'name'} = 'Cindy Crawford';
$tietag{'cindy'}{'address'} = 'YouBetIwouldLikeToKnowIt';
my $key;
foreach $key (keys %tietag) {
print $tietag{$key}{'name'}, "\t", $tietag{$key}{'address'},
"\n";
}
|