Debian Codegraph @

upstream/debian-unstable/man3/SDBM_File.3perl

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\" ========================================================================
56 .\"
57 .IX Title "SDBM_File 3perl"
58 .TH SDBM_File 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide"
59 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
60 .\" way too many mistakes in technical documents.
61 .if n .ad l
62 .nh
63 .SH NAME
64 SDBM_File \- Tied access to sdbm files
65 .SH SYNOPSIS
66 .IX Header "SYNOPSIS"
67 .Vb 2
68 \& use Fcntl; # For O_RDWR, O_CREAT, etc.
69 \& use SDBM_File;
70 \&
71 \& tie(%h, \*(AqSDBM_File\*(Aq, \*(Aqfilename\*(Aq, O_RDWR|O_CREAT, 0666)
72 \& or die "Couldn\*(Aqt tie SDBM file \*(Aqfilename\*(Aq: $!; aborting";
73 \&
74 \& # Now read and change the hash
75 \& $h{newkey} = newvalue;
76 \& print $h{oldkey};
77 \& ...
78 \&
79 \& untie %h;
80 .Ve
81 .SH DESCRIPTION
82 .IX Header "DESCRIPTION"
83 \&\f(CW\*(C`SDBM_File\*(C'\fR establishes a connection between a Perl hash variable and
84 a file in SDBM_File format. You can manipulate the data in the file
85 just as if it were in a Perl hash, but when your program exits, the
86 data will remain in the file, to be used the next time your program
87 runs.
88 .SS Tie
89 .IX Subsection "Tie"
90 Use \f(CW\*(C`SDBM_File\*(C'\fR with the Perl built-in \f(CW\*(C`tie\*(C'\fR function to establish
91 the connection between the variable and the file.
92 .PP
93 .Vb 1
94 \& tie %hash, \*(AqSDBM_File\*(Aq, $basename, $modeflags, $perms;
95 \&
96 \& tie %hash, \*(AqSDBM_File\*(Aq, $dirfile, $modeflags, $perms, $pagfilename;
97 .Ve
98 .PP
99 \&\f(CW$basename\fR is the base filename for the database. The database is two
100 files with ".dir" and ".pag" extensions appended to \f(CW$basename\fR,
101 .PP
102 .Vb 2
103 \& $basename.dir (or .sdbm_dir on VMS, per DIRFEXT constant)
104 \& $basename.pag
105 .Ve
106 .PP
107 The two filenames can also be given separately in full as \f(CW$dirfile\fR
108 and \f(CW$pagfilename\fR. This suits for two files without ".dir" and ".pag"
109 extensions, perhaps for example two files from File::Temp.
110 .PP
111 \&\f(CW$modeflags\fR can be the following constants from the \f(CW\*(C`Fcntl\*(C'\fR module (in
112 the style of the \fBopen\fR\|(2) system call),
113 .PP
114 .Vb 3
115 \& O_RDONLY read\-only access
116 \& O_WRONLY write\-only access
117 \& O_RDWR read and write access
118 .Ve
119 .PP
120 If you want to create the file if it does not already exist then bitwise-OR
121 (\f(CW\*(C`|\*(C'\fR) \f(CW\*(C`O_CREAT\*(C'\fR too. If you omit \f(CW\*(C`O_CREAT\*(C'\fR and the database does not
122 already exist then the \f(CW\*(C`tie\*(C'\fR call will fail.
123 .PP
124 .Vb 1
125 \& O_CREAT create database if doesn\*(Aqt already exist
126 .Ve
127 .PP
128 \&\f(CW$perms\fR is the file permissions bits to use if new database files are
129 created. This parameter is mandatory even when not creating a new database.
130 The permissions will be reduced by the user's umask so the usual value here
131 would be 0666, or if some very private data then 0600. (See
132 "umask" in perlfunc.)
133 .SH EXPORTS
134 .IX Header "EXPORTS"
135 SDBM_File optionally exports the following constants:
136 .IP \(bu 4
137 \&\f(CW\*(C`PAGFEXT\*(C'\fR \- the extension used for the page file, usually \f(CW\*(C`.pag\*(C'\fR.
138 .IP \(bu 4
139 \&\f(CW\*(C`DIRFEXT\*(C'\fR \- the extension used for the directory file, \f(CW\*(C`.dir\*(C'\fR
140 everywhere but VMS, where it is \f(CW\*(C`.sdbm_dir\*(C'\fR.
141 .IP \(bu 4
142 \&\f(CW\*(C`PAIRMAX\*(C'\fR \- the maximum size of a stored hash entry, including the
143 length of both the key and value.
144 .PP
145 These constants can also be used with fully qualified names,
146 eg. \f(CW\*(C`SDBM_File::PAGFEXT\*(C'\fR.
147 .SH DIAGNOSTICS
148 .IX Header "DIAGNOSTICS"
149 On failure, the \f(CW\*(C`tie\*(C'\fR call returns an undefined value and probably
150 sets \f(CW$!\fR to contain the reason the file could not be tied.
151 .ie n .SS """sdbm store returned \-1, errno 22, key ""..."" at ..."""
152 .el .SS "\f(CWsdbm store returned \-1, errno 22, key ""..."" at ...\fP"
153 .IX Subsection "sdbm store returned -1, errno 22, key ""..."" at ..."
154 This warning is emitted when you try to store a key or a value that
155 is too long. It means that the change was not recorded in the
156 database. See BUGS AND WARNINGS below.
157 .SH "SECURITY WARNING"
158 .IX Header "SECURITY WARNING"
159 \&\fBDo not accept SDBM files from untrusted sources!\fR
160 .PP
161 The sdbm file format was designed for speed and convenience, not for
162 portability or security. A maliciously crafted file might cause perl to
163 crash or even expose a security vulnerability.
164 .SH "BUGS AND WARNINGS"
165 .IX Header "BUGS AND WARNINGS"
166 There are a number of limits on the size of the data that you can
167 store in the SDBM file. The most important is that the length of a
168 key, plus the length of its associated value, may not exceed 1008
169 bytes.
170 .PP
171 See "tie" in perlfunc, perldbmfilter, Fcntl