Debian Codegraph @

upstream/opensuse-tumbleweed/man3/SDBM_File.3pm

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man v6.0.2 (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 .\" Required to disable full justification in groff 1.23.0.
57 .if n .ds AD l
58 .\" ========================================================================
59 .\"
60 .IX Title "SDBM_File 3pm"
61 .TH SDBM_File 3pm 2026-03-09 "perl v5.42.1" "Perl Programmers Reference Guide"
62 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
63 .\" way too many mistakes in technical documents.
64 .if n .ad l
65 .nh
66 .SH NAME
67 SDBM_File \- Tied access to sdbm files
68 .SH SYNOPSIS
69 .IX Header "SYNOPSIS"
70 .Vb 2
71 \& use Fcntl; # For O_RDWR, O_CREAT, etc.
72 \& use SDBM_File;
73 \&
74 \& tie(%h, \*(AqSDBM_File\*(Aq, \*(Aqfilename\*(Aq, O_RDWR|O_CREAT, 0666)
75 \& or die "Couldn\*(Aqt tie SDBM file \*(Aqfilename\*(Aq: $!; aborting";
76 \&
77 \& # Now read and change the hash
78 \& $h{newkey} = newvalue;
79 \& print $h{oldkey};
80 \& ...
81 \&
82 \& untie %h;
83 .Ve
84 .SH DESCRIPTION
85 .IX Header "DESCRIPTION"
86 \&\f(CW\*(C`SDBM_File\*(C'\fR establishes a connection between a Perl hash variable and
87 a file in SDBM_File format. You can manipulate the data in the file
88 just as if it were in a Perl hash, but when your program exits, the
89 data will remain in the file, to be used the next time your program
90 runs.
91 .SS Tie
92 .IX Subsection "Tie"
93 Use \f(CW\*(C`SDBM_File\*(C'\fR with the Perl built\-in \f(CW\*(C`tie\*(C'\fR function to establish
94 the connection between the variable and the file.
95 .PP
96 .Vb 1
97 \& tie %hash, \*(AqSDBM_File\*(Aq, $basename, $modeflags, $perms;
98 \&
99 \& tie %hash, \*(AqSDBM_File\*(Aq, $dirfile, $modeflags, $perms, $pagfilename;
100 .Ve
101 .PP
102 \&\f(CW$basename\fR is the base filename for the database. The database is two
103 files with ".dir" and ".pag" extensions appended to \f(CW$basename\fR,
104 .PP
105 .Vb 2
106 \& $basename.dir (or .sdbm_dir on VMS, per DIRFEXT constant)
107 \& $basename.pag
108 .Ve
109 .PP
110 The two filenames can also be given separately in full as \f(CW$dirfile\fR
111 and \f(CW$pagfilename\fR. This suits for two files without ".dir" and ".pag"
112 extensions, perhaps for example two files from File::Temp.
113 .PP
114 \&\f(CW$modeflags\fR can be the following constants from the \f(CW\*(C`Fcntl\*(C'\fR module (in
115 the style of the \fBopen\fR\|(2) system call),
116 .PP
117 .Vb 3
118 \& O_RDONLY read\-only access
119 \& O_WRONLY write\-only access
120 \& O_RDWR read and write access
121 .Ve
122 .PP
123 If you want to create the file if it does not already exist then bitwise\-OR
124 (\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
125 already exist then the \f(CW\*(C`tie\*(C'\fR call will fail.
126 .PP
127 .Vb 1
128 \& O_CREAT create database if doesn\*(Aqt already exist
129 .Ve
130 .PP
131 \&\f(CW$perms\fR is the file permissions bits to use if new database files are
132 created. This parameter is mandatory even when not creating a new database.
133 The permissions will be reduced by the user\*(Aqs umask so the usual value here
134 would be 0666, or if some very private data then 0600. (See
135 "umask" in perlfunc.)
136 .SH EXPORTS
137 .IX Header "EXPORTS"
138 SDBM_File optionally exports the following constants:
139 .IP \(bu 4
140 \&\f(CW\*(C`PAGFEXT\*(C'\fR \- the extension used for the page file, usually \f(CW\*(C`.pag\*(C'\fR.
141 .IP \(bu 4
142 \&\f(CW\*(C`DIRFEXT\*(C'\fR \- the extension used for the directory file, \f(CW\*(C`.dir\*(C'\fR
143 everywhere but VMS, where it is \f(CW\*(C`.sdbm_dir\*(C'\fR.
144 .IP \(bu 4
145 \&\f(CW\*(C`PAIRMAX\*(C'\fR \- the maximum size of a stored hash entry, including the
146 length of both the key and value.
147 .PP
148 These constants can also be used with fully qualified names,
149 eg. \f(CW\*(C`SDBM_File::PAGFEXT\*(C'\fR.
150 .SH DIAGNOSTICS
151 .IX Header "DIAGNOSTICS"
152 On failure, the \f(CW\*(C`tie\*(C'\fR call returns an undefined value and probably
153 sets \f(CW$!\fR to contain the reason the file could not be tied.
154 .ie n .SS """sdbm store returned \-1, errno 22, key ""..."" at ..."""
155 .el .SS "\f(CWsdbm store returned \-1, errno 22, key ""..."" at ...\fP"
156 .IX Subsection "sdbm store returned -1, errno 22, key ""..."" at ..."
157 This warning is emitted when you try to store a key or a value that
158 is too long. It means that the change was not recorded in the
159 database. See BUGS AND WARNINGS below.
160 .SH "SECURITY WARNING"
161 .IX Header "SECURITY WARNING"
162 \&\fBDo not accept SDBM files from untrusted sources!\fR
163 .PP
164 The sdbm file format was designed for speed and convenience, not for
165 portability or security. A maliciously crafted file might cause perl to
166 crash or even expose a security vulnerability.
167 .SH "BUGS AND WARNINGS"
168 .IX Header "BUGS AND WARNINGS"
169 There are a number of limits on the size of the data that you can
170 store in the SDBM file. The most important is that the length of a
171 key, plus the length of its associated value, may not exceed 1008
172 bytes.
173 .PP
174 See "tie" in perlfunc, perldbmfilter, Fcntl