in reply to dbmopen - if db file do this else do that

  • Comment on Re: dbmopen - if db file do this else do that

Replies are listed 'Best First'.
Re: Re: dbmopen - if db file do this else do that
by Anonymous Monk on May 04, 2002 at 00:34 UTC
    return 0 unless dbmopen %stored, $file, 0444;

    i actually tried that at first, but it creates a dbm file if none is there, so it always returns true :/ i'm trying to learn how to use AnyDBM and tie-ing the hash to a file. any pointers

Re: Re: dbmopen - if db file do this else do that
by perlplexer (Hermit) on May 04, 2002 at 00:55 UTC
    Yes, you are correct. This is from perldoc -f dbmopen
    If the database does not exist, it is created with protection specified by MASK (as modified by the "umask").
    Sorry for the confusion. Apparently, I was smoking something at the moment. ;)

    You can still improve your code by not using open() and using file tests instead; e.g.,
    sub validateSession{ my ($session, $file) = @_; my %stored; return 0 unless (-f "$file.dir" and -f "$file.pag") or -f "file.db"; return 0 unless dbmopen %$session, $file, 0444; %$session = %stored; dbmclose %stored; }
    --perlplexer