1ODBM_File(3pm) Perl Programmers Reference Guide ODBM_File(3pm)
2
3
4
6 ODBM_File - Tied access to odbm files
7
9 use Fcntl; # For O_RDWR, O_CREAT, etc.
10 use ODBM_File;
11
12 # Now read and change the hash
13 $h{newkey} = newvalue;
14 print $h{oldkey};
15 ...
16
17 untie %h;
18
20 "ODBM_File" establishes a connection between a Perl hash variable and a
21 file in ODBM_File format;. You can manipulate the data in the file
22 just as if it were in a Perl hash, but when your program exits, the
23 data will remain in the file, to be used the next time your program
24 runs.
25
26 Use "ODBM_File" with the Perl built-in "tie" function to establish the
27 connection between the variable and the file. The arguments to "tie"
28 should be:
29
30 1. The hash variable you want to tie.
31
32 2. The string "ODBM_File". (Ths tells Perl to use the "ODBM_File"
33 package to perform the functions of the hash.)
34
35 3. The name of the file you want to tie to the hash.
36
37 4. Flags. Use one of:
38
39 "O_RDONLY"
40 Read-only access to the data in the file.
41
42 "O_WRONLY"
43 Write-only access to the data in the file.
44
45 "O_RDWR"
46 Both read and write access.
47
48 If you want to create the file if it does not exist, add "O_CREAT"
49 to any of these, as in the example. If you omit "O_CREAT" and the
50 file does not already exist, the "tie" call will fail.
51
52 5. The default permissions to use if a new file is created. The
53 actual permissions will be modified by the user's umask, so you
54 should probably use 0666 here. (See "umask" in perlfunc.)
55
57 On failure, the "tie" call returns an undefined value and probably sets
58 $! to contain the reason the file could not be tied.
59
60 "odbm store returned -1, errno 22, key "..." at ..."
61 This warning is emitted when you try to store a key or a value that is
62 too long. It means that the change was not recorded in the database.
63 See BUGS AND WARNINGS below.
64
66 Do not accept ODBM files from untrusted sources.
67
68 On modern Linux systems these are typically GDBM files, which are not
69 portable across platforms.
70
71 The GDBM documentation doesn't imply that files from untrusted sources
72 can be safely used with "libgdbm".
73
74 Systems that don't use GDBM compatibilty for old dbm support will be
75 using a platform specific library, possibly inherited from BSD systems,
76 where it may or may not be safe to use an untrusted file.
77
78 A maliciously crafted file might cause perl to crash or even expose a
79 security vulnerability.
80
82 There are a number of limits on the size of the data that you can store
83 in the ODBM file. The most important is that the length of a key, plus
84 the length of its associated value, may not exceed 1008 bytes.
85
86 See "tie" in perlfunc, perldbmfilter, Fcntl
87
88
89
90perl v5.34.1 2022-03-15 ODBM_File(3pm)