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

Re: [MacPerl] DBM & Mac Perl



Stephane Jose <jose.stephane@uqam.ca> wrote
>Hi,
>
>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.
>
>I don't know where to start and I am a bit confused with MacPerl's
>implementation of DBM files.
>
>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.
>
>This brings also two questions:
>
>1 - Would a dbm file created by MacPerl be portable to Unix environment?
>
>2 - How can I convert my text file database to the dbm format
>
>I have been looking for info in the excellent MacPerl List Archives but I
>couldn't find satisfying answers.
>
>Can somedy help me on this one? TIA.
>
>Stef
>
Hello,
      
1. I very much doubt that dbm files are portable - they are binary. You
can't even move them across Unix machines e.g. from a Sun running SunOS to a PC
running Linux. (I tried, but then I realised I was being silly, after it 
didn't work).

2. I'd write a perl program to filter your flat text to a dbm file format.
if you have tab-delimited records you could do something like

while (<INFILE>) {
        my($key,$value) = split(/\t/);
        $hash{$key} = $value;
}

Of course, the hash needs to be tie'd to a file (see documentation for perltie).

If you want to "future-proof" your data, I'd suggest using SGML to mark it up
logically then maintain this. You can then write perl code to transform this 
data into a dbm format, which you can use to search quickly. (Or you can write
filters to convert it to whatever-you-want-today, or
whatever-you-want-next-year).

Bob


________________________________________________________________
          Bob Wilkinson, Perl Programmer, Pindar plc
Tel: +44 (0)1904 613040    Email: B.Wilkinson@pindar.co.uk
Fax: +44 (0)1904 613110    URL: http://www.connection.co.uk/bob
________________________________________________________________
  I don't speak for my employer - er, they made me say that..
________________________________________________________________