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

Re: [MacPerl] DB_File File Size




4/23/99, Matt Henderson wrote:
    >    #! Perl
    >
    >    use DB_File;
    >
    >    my $name = "my_db.dbm";
    >
    >    tie(%$name, 'DB_File', $name, O_RDWR|O_CREAT, 0644);
    >
    >    for ($i = 1; $i < 10; $i++) {
    >         $$name{$i} = time;
    >    }
    >
    >    untie(%$name);
    >
    >
    >This resulted in a file on my Mac, "my_db.dbm," that was
    >*2.5 megabytes*     >in size! (Allowing $i to run to 100
    >crashed MacPerl when the DB file was *128 megabytes.*)
    >Surely that can't be normal behavior. Have I done something
    >obviously wrong here?

    >Thanks in advance.
    >
    >    -- Matt


Dear Matt,

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.

To enable the compiler to help you avoid such confusing situations, start
your scripts off with:

    #!/usr/bin/perl -w
    use diagnostics ;
    use strict ;


Best of luck,
rkm


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