Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
2.6 KiB

  1. package SDBM_File;
  2. use strict;
  3. use warnings;
  4. require Tie::Hash;
  5. use XSLoader ();
  6. our @ISA = qw(Tie::Hash);
  7. our $VERSION = "1.03" ;
  8. XSLoader::load 'SDBM_File', $VERSION;
  9. 1;
  10. __END__
  11. =head1 NAME
  12. SDBM_File - Tied access to sdbm files
  13. =head1 SYNOPSIS
  14. use Fcntl; # For O_RDWR, O_CREAT, etc.
  15. use SDBM_File;
  16. tie(%h, 'SDBM_File', 'filename', O_RDWR|O_CREAT, 0666)
  17. or die "Couldn't tie SDBM file 'filename': $!; aborting";
  18. # Now read and change the hash
  19. $h{newkey} = newvalue;
  20. print $h{oldkey};
  21. ...
  22. untie %h;
  23. =head1 DESCRIPTION
  24. C<SDBM_File> establishes a connection between a Perl hash variable and
  25. a file in SDBM_File format;. You can manipulate the data in the file
  26. just as if it were in a Perl hash, but when your program exits, the
  27. data will remain in the file, to be used the next time your program
  28. runs.
  29. Use C<SDBM_File> with the Perl built-in C<tie> function to establish
  30. the connection between the variable and the file. The arguments to
  31. C<tie> should be:
  32. =over 4
  33. =item 1.
  34. The hash variable you want to tie.
  35. =item 2.
  36. The string C<"SDBM_File">. (Ths tells Perl to use the C<SDBM_File>
  37. package to perform the functions of the hash.)
  38. =item 3.
  39. The name of the file you want to tie to the hash.
  40. =item 4.
  41. Flags. Use one of:
  42. =over 2
  43. =item C<O_RDONLY>
  44. Read-only access to the data in the file.
  45. =item C<O_WRONLY>
  46. Write-only access to the data in the file.
  47. =item C<O_RDWR>
  48. Both read and write access.
  49. =back
  50. If you want to create the file if it does not exist, add C<O_CREAT> to
  51. any of these, as in the example. If you omit C<O_CREAT> and the file
  52. does not already exist, the C<tie> call will fail.
  53. =item 5.
  54. The default permissions to use if a new file is created. The actual
  55. permissions will be modified by the user's umask, so you should
  56. probably use 0666 here. (See L<perlfunc/umask>.)
  57. =back
  58. =head1 DIAGNOSTICS
  59. On failure, the C<tie> call returns an undefined value and probably
  60. sets C<$!> to contain the reason the file could not be tied.
  61. =head2 C<sdbm store returned -1, errno 22, key "..." at ...>
  62. This warning is emmitted when you try to store a key or a value that
  63. is too long. It means that the change was not recorded in the
  64. database. See BUGS AND WARNINGS below.
  65. =head1 BUGS AND WARNINGS
  66. There are a number of limits on the size of the data that you can
  67. store in the SDBM file. The most important is that the length of a
  68. key, plus the length of its associated value, may not exceed 1008
  69. bytes.
  70. See L<perlfunc/tie>, L<perldbmfilter>, L<Fcntl>
  71. =cut