9 our @ISA = qw(Tie::Hash);
10 our $VERSION = "1.13";
12 our @EXPORT_OK = qw(PAGFEXT DIRFEXT PAIRMAX);
13 use Exporter "import";
23 SDBM_File - Tied access to sdbm files
27 use Fcntl; # For O_RDWR, O_CREAT, etc.
30 tie(%h, 'SDBM_File', 'filename', O_RDWR|O_CREAT, 0666)
31 or die "Couldn't tie SDBM file 'filename': $!; aborting";
33 # Now read and change the hash
34 $h{newkey} = newvalue;
42 C<SDBM_File> establishes a connection between a Perl hash variable and
43 a file in SDBM_File format. You can manipulate the data in the file
44 just as if it were in a Perl hash, but when your program exits, the
45 data will remain in the file, to be used the next time your program
50 Use C<SDBM_File> with the Perl built-in C<tie> function to establish
51 the connection between the variable and the file.
53 tie %hash, 'SDBM_File', $basename, $modeflags, $perms;
55 tie %hash, 'SDBM_File', $dirfile, $modeflags, $perms, $pagfilename;
57 C<$basename> is the base filename for the database. The database is two
58 files with ".dir" and ".pag" extensions appended to C<$basename>,
60 $basename.dir (or .sdbm_dir on VMS, per DIRFEXT constant)
63 The two filenames can also be given separately in full as C<$dirfile>
64 and C<$pagfilename>. This suits for two files without ".dir" and ".pag"
65 extensions, perhaps for example two files from L<File::Temp>.
67 C<$modeflags> can be the following constants from the C<Fcntl> module (in
68 the style of the L<open(2)> system call),
70 O_RDONLY read-only access
71 O_WRONLY write-only access
72 O_RDWR read and write access
74 If you want to create the file if it does not already exist then bitwise-OR
75 (C<|>) C<O_CREAT> too. If you omit C<O_CREAT> and the database does not
76 already exist then the C<tie> call will fail.
78 O_CREAT create database if doesn't already exist
80 C<$perms> is the file permissions bits to use if new database files are
81 created. This parameter is mandatory even when not creating a new database.
82 The permissions will be reduced by the user's umask so the usual value here
83 would be 0666, or if some very private data then 0600. (See
88 SDBM_File optionally exports the following constants:
94 C<PAGFEXT> - the extension used for the page file, usually C<.pag>.
98 C<DIRFEXT> - the extension used for the directory file, C<.dir>
99 everywhere but VMS, where it is C<.sdbm_dir>.
103 C<PAIRMAX> - the maximum size of a stored hash entry, including the
104 length of both the key and value.
108 These constants can also be used with fully qualified names,
109 eg. C<SDBM_File::PAGFEXT>.
113 On failure, the C<tie> call returns an undefined value and probably
114 sets C<$!> to contain the reason the file could not be tied.
116 =head2 C<sdbm store returned -1, errno 22, key "..." at ...>
118 This warning is emitted when you try to store a key or a value that
119 is too long. It means that the change was not recorded in the
120 database. See BUGS AND WARNINGS below.
122 =head1 BUGS AND WARNINGS
124 There are a number of limits on the size of the data that you can
125 store in the SDBM file. The most important is that the length of a
126 key, plus the length of its associated value, may not exceed 1008
129 See L<perlfunc/tie>, L<perldbmfilter>, L<Fcntl>