Seth Woolley's Man Viewer

SDBM_File(3) - SDBM_File - Tied access to sdbm files - man 3 SDBM_File

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

SDBM_File(3)           Perl Programmers Reference Guide           SDBM_File(3)



NAME
       SDBM_File - Tied access(2,5) to sdbm files

SYNOPSIS
        use Fcntl;   # For O_RDWR, O_CREAT, etc.
        use SDBM_File;

        tie(%h, 'SDBM_File', 'filename', O_RDWR|O_CREAT, 0666)
          or die "Couldn't tie SDBM file(1,n) 'filename': $!; aborting";

        # Now read(2,n,1 builtins) and change the hash
        $h{newkey} = newvalue;
        print $h{oldkey};
        ...

        untie %h;

DESCRIPTION
       "SDBM_File" establishes a connection between a Perl hash variable and a
       file(1,n) in(1,8) SDBM_File format;.  You can manipulate the data in(1,8) the file(1,n)
       just as if(3,n) it were in(1,8) a Perl hash, but when your program exits, the
       data will remain in(1,8) the file(1,n), to be used the next time(1,2,n) your program
       runs.

       Use "SDBM_File" with the Perl built-in "tie" function to establish the
       connection between the variable and the file.  The arguments to "tie"
       should be:

       1.  The hash variable you want to tie.

       2.  The string(3,n) "SDBM_File".  (Ths tells Perl to use the "SDBM_File"
           package to perform the functions of the hash.)

       3.  The name of the file(1,n) you want to tie to the hash.

       4.  Flags.  Use one of:

           "O_RDONLY"
             Read-only access(2,5) to the data in(1,8) the file.

           "O_WRONLY"
             Write-only access(2,5) to the data in(1,8) the file.

           "O_RDWR"
             Both read(2,n,1 builtins) and write(1,2) access.

           If you want to create the file(1,n) if(3,n) it does not exist, add "O_CREAT"
           to any of these, as in(1,8) the example.  If you omit "O_CREAT" and the
           file(1,n) does not already exist, the "tie" call will fail.

       5.  The default permissions to use if(3,n) a new file(1,n) is created.  The
           actual permissions will be modified by the user's umask, so you
           should probably use 0666 here. (See "umask" in(1,8) perlfunc.)

DIAGNOSTICS
       On failure, the "tie" call returns an undefined value and probably sets
       $! to contain the reason the file(1,n) could not be tied.

       "sdbm store returned -1, errno 22, key "..." at ..."

       This warning is emmitted when you try to store a key or a value that is
       too long.  It means that the change was not recorded in(1,8) the database.
       See BUGS AND WARNINGS below.

BUGS AND WARNINGS
       There are a number of limits on the size of the data that you can store
       in(1,8) the SDBM file.  The most important is that the length of a key, plus
       the length of its associated value, may not exceed 1008 bytes.

       See "tie" in(1,8) perlfunc, perldbmfilter, Fcntl



perl v5.8.5                       2001-09-21                      SDBM_File(3)

References for this manual (incoming links)