9 our @ISA = qw(Tie::Hash);
10 our $VERSION = "1.15";
20 NDBM_File - Tied access to ndbm files
24 use Fcntl; # For O_RDWR, O_CREAT, etc.
27 tie(%h, 'NDBM_File', 'filename', O_RDWR|O_CREAT, 0666)
28 or die "Couldn't tie NDBM file 'filename': $!; aborting";
30 # Now read and change the hash
31 $h{newkey} = newvalue;
39 C<NDBM_File> establishes a connection between a Perl hash variable and
40 a file in NDBM_File format;. You can manipulate the data in the file
41 just as if it were in a Perl hash, but when your program exits, the
42 data will remain in the file, to be used the next time your program
45 Use C<NDBM_File> with the Perl built-in C<tie> function to establish
46 the connection between the variable and the file. The arguments to
53 The hash variable you want to tie.
57 The string C<"NDBM_File">. (Ths tells Perl to use the C<NDBM_File>
58 package to perform the functions of the hash.)
62 The name of the file you want to tie to the hash.
72 Read-only access to the data in the file.
76 Write-only access to the data in the file.
80 Both read and write access.
84 If you want to create the file if it does not exist, add C<O_CREAT> to
85 any of these, as in the example. If you omit C<O_CREAT> and the file
86 does not already exist, the C<tie> call will fail.
90 The default permissions to use if a new file is created. The actual
91 permissions will be modified by the user's umask, so you should
92 probably use 0666 here. (See L<perlfunc/umask>.)
98 On failure, the C<tie> call returns an undefined value and probably
99 sets C<$!> to contain the reason the file could not be tied.
101 =head2 C<ndbm store returned -1, errno 22, key "..." at ...>
103 This warning is emitted when you try to store a key or a value that
104 is too long. It means that the change was not recorded in the
105 database. See BUGS AND WARNINGS below.
107 =head1 SECURITY AND PORTABILITY
109 B<Do not accept NDBM files from untrusted sources.>
111 On modern Linux systems these are typically GDBM files, which are not
112 portable across platforms.
114 The GDBM documentation doesn't imply that files from untrusted sources
115 can be safely used with C<libgdbm>.
117 Systems that don't use GDBM compatibilty for ndbm support will be
118 using a platform specific library, possibly inherited from BSD
119 systems, where it may or may not be safe to use an untrusted file.
121 A maliciously crafted file might cause perl to crash or even expose a
122 security vulnerability.
124 =head1 BUGS AND WARNINGS
126 There are a number of limits on the size of the data that you can
127 store in the NDBM file. The most important is that the length of a
128 key, plus the length of its associated value, may not exceed 1008
131 See L<perlfunc/tie>, L<perldbmfilter>, L<Fcntl>