1package AnyDBM_File; 2use warnings; 3use strict; 4 5use 5.006_001; 6our $VERSION = '1.01'; 7our @ISA = qw(NDBM_File DB_File GDBM_File SDBM_File ODBM_File) unless @ISA; 8 9my $mod; 10for $mod (@ISA) { 11 if (eval "require $mod") { 12 @ISA = ($mod); # if we leave @ISA alone, warnings abound 13 return 1; 14 } 15} 16 17die "No DBM package was successfully found or installed"; 18 19__END__ 20 21=head1 NAME 22 23AnyDBM_File - provide framework for multiple DBMs 24 25=head1 SYNOPSIS 26 27 use AnyDBM_File; 28 29=head1 DESCRIPTION 30 31This module is a "pure virtual base class"--it has nothing of its own. 32It's just there to inherit from one of the various DBM packages. It 33prefers ndbm for compatibility reasons with Perl 4, then Berkeley DB (See 34L<DB_File>), GDBM, SDBM (which is always there--it comes with Perl), and 35finally ODBM. This way old programs that used to use NDBM via dbmopen() 36can still do so, but new ones can reorder @ISA: 37 38 BEGIN { @AnyDBM_File::ISA = qw(DB_File GDBM_File NDBM_File) } 39 use AnyDBM_File; 40 41Having multiple DBM implementations makes it trivial to copy database formats: 42 43 use Fcntl; use NDBM_File; use DB_File; 44 tie %newhash, 'DB_File', $new_filename, O_CREAT|O_RDWR; 45 tie %oldhash, 'NDBM_File', $old_filename, 1, 0; 46 %newhash = %oldhash; 47 48=head2 DBM Comparisons 49 50Here's a partial table of features the different packages offer: 51 52 odbm ndbm sdbm gdbm bsd-db 53 ---- ---- ---- ---- ------ 54 Linkage comes w/ perl yes yes yes yes yes 55 Src comes w/ perl no no yes no no 56 Comes w/ many unix os yes yes[0] no no no 57 Builds ok on !unix ? ? yes yes ? 58 Code Size ? ? small big big 59 Database Size ? ? small big? ok[1] 60 Speed ? ? slow ok fast 61 FTPable no no yes yes yes 62 Easy to build N/A N/A yes yes ok[2] 63 Size limits 1k 4k 1k[3] none none 64 Byte-order independent no no no no yes 65 Licensing restrictions ? ? no yes no 66 67 68=over 4 69 70=item [0] 71 72on mixed universe machines, may be in the bsd compat library, 73which is often shunned. 74 75=item [1] 76 77Can be trimmed if you compile for one access method. 78 79=item [2] 80 81See L<DB_File>. 82Requires symbolic links. 83 84=item [3] 85 86By default, but can be redefined. 87 88=back 89 90=head1 SEE ALSO 91 92dbm(3), ndbm(3), DB_File(3), L<perldbmfilter> 93 94=cut 95