[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] DBM & Mac Perl



Stephane Jose <jose.stephane@uqam.ca> writes:
>I have built a custom database system based on a flat text file (return
>delimited records, tab delimited fields). As the database file grows I'd
>like to modify the system to use a dbm file instead.
[...]
>The Llama and Camel references mention that when calling dbmopen, Perl
>should create a pair of disk file (somefile.pag and somefile.dir). MacPerl
>only create one file. I do not understand why.

The two files Llama and Camel talked about are created in some traditional
dbm implementations. MacPerl users a different one, which cretes only one
file.

>This brings also two questions:
>
>1 - Would a dbm file created by MacPerl be portable to Unix environment?

No. There is no single Unix dbm file format, so Unix dbm fiels are not
platform independent either.

>2 - How can I convert my text file database to the dbm format

First, make sure you understand and can live with the fundamental design
characteristic of dbm: That it only supports a single, exact-match, key.
Assuming that's ok for your DB, and tht your DB has been of the form

Key<Tab>value<CR>
...

you can convert with

dbmopen(%DB, "MyDB", 0666);

while (<TEXTDB>) {
   chomp;
   /(.*?)\t(.*)/;
   $DB{$1} = $2;
}

dbmclose(%DB);

Matthias

-----
Matthias Neeracher   <neeri@iis.ee.ethz.ch>   http://www.iis.ee.ethz.ch/~neeri
    "The key, the whole key, and nothing but the key. So help me Codd."