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

Re: [MacPerl] DB_File File Size



Richard K. Moore wrote:

> Being a newbie, I was waiting for someone else to answer your question.
> Since no one has (as yet, on list), I'll take a stab at it.
>
> At the time you execute tie, the scalar $name is a string holding a file
> name.  You are telling tie that this string value is to be interpreted as a
> pointer to a hash as well as being interpreted as the name of the tied file
> ".  If you want to track down how Perl deals with these bizarre
> instructions, you might run your program with a value like two or three,
> instead of 10, and print out (keys %$name), etc., at the end.
>
> To fix the problem, use a different variable, like $hash, for the tied
> hash, and initialize it to " = {} " before calling tie.

Thanks very much for the reply. Unfortunately, though, unless I'm
misunderstanding your point, it didn't work for me. The following code
produces the exact same (huge dbm file) results:

    #! Perl

    use DB_File;

    my $name = ":my_db";
    my %hash = ();

    tie(%hash, 'DB_File', $name.".dbm", O_RDWR|O_CREAT, 0644);

    for ($i = 1; $i < 10; $i++) {
         $hash{$i} = time;
    }

    untie(%hash);

I didn't really think this would solve the problems, since I've implemented
several websites under UNIX using the previous code that I posted (something
similar actually, not precisely the same)-- and they all work fine. In fact,
I've found it convenient to let the tied hash share the same name as part of
the file, i.e.

    tie(%$name, 'DB_File', $name.".dbm",  O_RDWR|O_CREAT, 0644);

Doing it this way makes it convenient to define subroutines for managing the
opening and closing of DB files, e.g.

    db_open($name,$WRITELOCK)

...and having to only pass two parameters (the name of the hash/filename,
and the access mode.

Also worth noting... if, on the Mac, I simply switch from DB_File to
AnyDBM_File, then the resulting DB files are very small. So I get the
feeling the problem is somehow related to the DB_File implementation on the
MacOS (or MacPerl, or whatever actually implements that format.)

For various reasons, though, AnyDBM_File is inconvenient for me under UNIX,
since it defaults to a DB implementation that has an field-size limit of 1k.
So I really need to be able to use DB_File.

Thanks again for your response, and please let me know if I've misunderstood
something.

Kind regards,

Matt Henderson   |   matt@exponet.net   |    www.exponet.net
                 .                      .
E x p o n e t   M e d i a  T e c h n o l o g i e s   G m b H
Full-Service Web Development & Engineering Services Provider


===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org