Gerry Hickman:
# Does anyone know if it's possible to achieve basic flat-file
# database functionality in Perl without a "real" database?
#
# The Raq-4 server I work on has PERL 5, but the guy won't
# install MySQL and doesn't want to enable Interbase.
#
# I currently have a text file with a pipe (|) for the field
# delimiter. It sort of works but it's like something out of the Ark!
One possibility is DBM files. DBMs are something like on-disk hashes.
Perl comes with one of the formats, SDBM, on Windows. It looks like
this:
dbmopen %data, 'databases\trek', 0666 or die "Can't open trek:
$!";
#Manipulate %data here
dbmclose %data;
DBMs are probably faster than flat files, unless you're reading in and
manipulating every single record every time the program runs, in which
case it might be a bit slower.
You can store anything you want into %data, except for references. For
that, you can use one of several modules for serialization. My favorite
is Storable:
use Storable qw(freeze thaw);
dbmopen %data, 'databases\trek', 0666 or die "Can't open trek:
$!";
$captains=[
{ first => 'James', last => 'Kirk', ships => [
'NCC-1701', 'NCC-1701-A' ] },
{ first => 'Jean-Luc', last => 'Picard', ships => [
'NCC-1701-D', 'NCC-1701-E' ] },
{ first => 'Benjamin', last => 'Sisko', ships => [
'NX-72905' ] },
{ first => 'Kathryn', last => 'Janeway', ships => [
'NCC-72905' ] },
{ first => 'Jonathan', last => 'Archer', ships => [
'NX-01' ] }
];
$data{'Captains'}=freeze($captains);
$captains=thaw($data{'Captains'});
dbmclose %data;
Hope this helps.
--Brent Dax <[EMAIL PROTECTED]>
@roles=map {"Parrot $_"} qw(embedding regexen Configure)
Early in the series, Patrick Stewart came up to us and asked how warp
drive worked. We explained some of the hypothetical principles . . .
"Nonsense," Patrick declared. "All you have to do is say, 'Engage.'"
--Star Trek: The Next Generation Technical Manual
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs