Current Issue


Table of contents

CD-ROM

Sys Admin and The Perl Journal CD-ROM version 12.0

Version 12.0 delivers every issue of Sys Admin from 1992 through 2006 and every
issue of The Perl Journal from 1996-2002 in one convenient CD-ROM!

Order now!

Sys Admin Magazine > Archives > 2004 > July 2004

Lightweight Persistent Data

Randal L. Schwartz

Frequently, you have data with a strong will to live. That is, your data must persist between invocations of your program and occasionally even be shared between simultaneous invocations.

At the high end of this demand, we have entire companies devoted to creating high-performance, multi-user, SQL-interfaced databases. These databases are usually accessed from Perl via the DBI package, or by some wrapper slightly above DBI, such as Class::DBI or DBIx::SQLEngine. The details of SQL might even be entirely hidden away using a higher level package like Tangram or Alzabo.

But further down the scale, there are some new solutions popping onto the scene, which invite further observation, as well as some old classic solutions. For example, since Perl version 2 we've been able to put a hash out on disk with dbmopen:

dbmopen(%HASH, "/path/on/disk", 0644) || die;
$HASH{"key"} = "value";
dbmclose(%HASH);
The effect of such code is that we now have a key/value pair stored in an external structured file. We can later come along and reopen the database as a hash again, and treat it as if it were a hash with preexisting values:

dbmopen(%HASH, "/path/on/disk", 0644) || die;
foreach $key (sort keys %HASH) {
  print "$key => $HASH{$key}\n";
}
dbmclose(%HASH);
While the interface was relatively simple, I wrote quite a few programs before Perl5 came around using this storage mechanism for my persistence. However, this storage suffered some limitations: the keys and values had to be under a given size, access to the structure could not handle multi-user reads and writes, and the resulting data files were not necessarily portable to other machines (because they used incompatible libraries or byte orders).



MarketPlace

Free Download Speeds Up PCs
Make Your PC Faster --New Diskeeper 2008 Speeds Up PCs --Download Free Trial Now!

Villanova University Six Sigma & IT Certificate Programs
100% Online programs in Six Sigma, IS Security, CISSP Prep, Business Analysis, Proj. Mgmt. and more!

Automate Software Builds with Visual Build Pro
Easily create an automated, repeatable process for building and deploying software.

WinDev 12 - Powerful IDE
Develop 10 times faster ! ALM, IDE, .Net, RAD, 5GL, Database, 5GL, 64-bit, etc. Free Express version

Wanna see your ad here?