1NDBM_File(3pm)         Perl Programmers Reference Guide         NDBM_File(3pm)
2
3
4

NAME

6       NDBM_File - Tied access to ndbm files
7

SYNOPSIS

9         use Fcntl;   # For O_RDWR, O_CREAT, etc.
10         use NDBM_File;
11
12         tie(%h, 'NDBM_File', 'filename', O_RDWR|O_CREAT, 0666)
13           or die "Couldn't tie NDBM file 'filename': $!; aborting";
14
15         # Now read and change the hash
16         $h{newkey} = newvalue;
17         print $h{oldkey};
18         ...
19
20         untie %h;
21

DESCRIPTION

23       "NDBM_File" establishes a connection between a Perl hash variable and a
24       file in NDBM_File format;.  You can manipulate the data in the file
25       just as if it were in a Perl hash, but when your program exits, the
26       data will remain in the file, to be used the next time your program
27       runs.
28
29       Use "NDBM_File" with the Perl built-in "tie" function to establish the
30       connection between the variable and the file.  The arguments to "tie"
31       should be:
32
33       1.  The hash variable you want to tie.
34
35       2.  The string "NDBM_File".  (Ths tells Perl to use the "NDBM_File"
36           package to perform the functions of the hash.)
37
38       3.  The name of the file you want to tie to the hash.
39
40       4.  Flags.  Use one of:
41
42           "O_RDONLY"
43             Read-only access to the data in the file.
44
45           "O_WRONLY"
46             Write-only access to the data in the file.
47
48           "O_RDWR"
49             Both read and write access.
50
51           If you want to create the file if it does not exist, add "O_CREAT"
52           to any of these, as in the example.  If you omit "O_CREAT" and the
53           file does not already exist, the "tie" call will fail.
54
55       5.  The default permissions to use if a new file is created.  The
56           actual permissions will be modified by the user's umask, so you
57           should probably use 0666 here. (See "umask" in perlfunc.)
58

DIAGNOSTICS

60       On failure, the "tie" call returns an undefined value and probably sets
61       $! to contain the reason the file could not be tied.
62
63   "ndbm store returned -1, errno 22, key "..." at ..."
64       This warning is emitted when you try to store a key or a value that is
65       too long.  It means that the change was not recorded in the database.
66       See BUGS AND WARNINGS below.
67

SECURITY AND PORTABILITY

69       Do not accept NDBM files from untrusted sources.
70
71       On modern Linux systems these are typically GDBM files, which are not
72       portable across platforms.
73
74       The GDBM documentation doesn't imply that files from untrusted sources
75       can be safely used with "libgdbm".
76
77       Systems that don't use GDBM compatibilty for ndbm support will be using
78       a platform specific library, possibly inherited from BSD systems, where
79       it may or may not be safe to use an untrusted file.
80
81       A maliciously crafted file might cause perl to crash or even expose a
82       security vulnerability.
83

BUGS AND WARNINGS

85       There are a number of limits on the size of the data that you can store
86       in the NDBM file.  The most important is that the length of a key, plus
87       the length of its associated value, may not exceed 1008 bytes.
88
89       See "tie" in perlfunc, perldbmfilter, Fcntl
90
91
92
93perl v5.38.2                      2023-11-30                    NDBM_File(3pm)
Impressum