1NDBM_File(3pm) Perl Programmers Reference Guide NDBM_File(3pm)
2
3
4
6 NDBM_File - Tied access to ndbm files
7
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
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
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
69 There are a number of limits on the size of the data that you can store
70 in the NDBM file. The most important is that the length of a key, plus
71 the length of its associated value, may not exceed 1008 bytes.
72
73 See "tie" in perlfunc, perldbmfilter, Fcntl
74
75
76
77perl v5.12.4 2011-06-07 NDBM_File(3pm)