Redo #7679 with LFs instead of CRLFs.
[p5sagit/p5-mst-13.2.git] / ext / SDBM_File / SDBM_File.pm
CommitLineData
a0d0e21e 1package SDBM_File;
2
ed3c51d2 3use strict;
ed3c51d2 4
5require Tie::Hash;
9426adcd 6use XSLoader ();
a0d0e21e 7
17f410f9 8our @ISA = qw(Tie::Hash);
9our $VERSION = "1.02" ;
c07a80fd 10
9426adcd 11XSLoader::load 'SDBM_File', $VERSION;
a0d0e21e 12
131;
14
15__END__
a5f75d66 16
17=head1 NAME
18
19SDBM_File - Tied access to sdbm files
20
21=head1 SYNOPSIS
22
f75fd8c0 23 use Fcntl; # For O_RDWR, O_CREAT, etc.
a5f75d66 24 use SDBM_File;
25
f75fd8c0 26 tie(%h, 'SDBM_File', 'filename', O_RDWR|O_CREAT, 0666)
27 or die "Couldn't tie SDBM file 'filename': $!; aborting";
28
29 # Now read and change the hash
30 $h{newkey} = newvalue;
31 print $h{oldkey};
32 ...
a5f75d66 33
34 untie %h;
35
36=head1 DESCRIPTION
37
f75fd8c0 38C<SDBM_File> establishes a connection between a Perl hash variable and
39a file in SDBM_File format;. You can manipulate the data in the file
40just as if it were in a Perl hash, but when your program exits, the
41data will remain in the file, to be used the next time your program
42runs.
43
44Use C<SDBM_File> with the Perl built-in C<tie> function to establish
45the connection between the variable and the file. The arguments to
46C<tie> should be:
47
48=over 4
49
50=item 1.
51
52The hash variable you want to tie.
53
54=item 2.
55
56The string C<"SDBM_File">. (Ths tells Perl to use the C<SDBM_File>
57package to perform the functions of the hash.)
58
59=item 3.
60
61The name of the file you want to tie to the hash.
62
63=item 4.
64
65Flags. Use one of:
66
67=over 2
68
69=item C<O_RDONLY>
70
71Read-only access to the data in the file.
72
73=item C<O_WRONLY>
74
75Write-only access to the data in the file.
76
77=item C<O_RDWR>
78
79Both read and write access.
80
81=back
82
83If you want to create the file if it does not exist, add C<O_CREAT> to
84any of these, as in the example. If you omit C<O_CREAT> and the file
85does not already exist, the C<tie> call will fail.
86
87=item 5.
88
89The default permissions to use if a new file is created. The actual
90permissions will be modified by the user's umask, so you should
91probably use 0666 here. (See L<perlfunc/umask>.)
92
93=back
94
95=head1 DIAGNOSTICS
96
97On failure, the C<tie> call returns an undefined value and probably
98sets C<$!> to contain the reason the file could not be tied.
99
100=head2 C<sdbm store returned -1, errno 22, key "..." at ...>
101
102This warning is emmitted when you try to store a key or a value that
103is too long. It means that the change was not recorded in the
104database. See BUGS AND WARNINGS below.
105
f75fd8c0 106=head1 BUGS AND WARNINGS
107
108There are a number of limits on the size of the data that you can
109store in the SDBM file. The most important is that the length of a
110key, plus the length of its associated value, may not exceed 1008
111bytes.
112
113See L<perlfunc/tie>, L<perldbmfilter>, L<Fcntl>
a5f75d66 114
115=cut