ЭЛЕКТРОННАЯ БИБЛИОТЕКА КОАПП |
Сборники Художественной, Технической, Справочной, Английской, Нормативной, Исторической, и др. литературы. |
7.2.1 AnyDBM_File - Provide Framework for Multiple DBMsuse AnyDBM_File; This module is a "pure virtual base class" - it has nothing of its own. It's just there to inherit from the various DBM packages. By default it inherits from NDBM_File for compatibility with earlier versions of Perl. If it doesn't find NDBM_File, it looks for DB_File, GDBM_File, SDBM_File (which is always there - it comes with Perl), and finally ODBM_File. Perl's dbmopen function (which now exists only for backward compatibility) actually just calls tie to bind a hash to AnyDBM_File. The effect is to bind the hash to one of the specific DBM classes that AnyDBM_File inherits from. You can override the defaults and determine which class dbmopen will tie to. Do this by redefining @ISA: @AnyDBM_File::ISA = qw(DB_File GDBM_File NDBM_File); Note, however, that an explicit use takes priority over the ordering of @ISA, so that: use GDBM_File; will cause the next dbmopen to tie your hash to GDBM_File. You can tie hash variables directly to the desired class yourself, without using dbmopen or AnyDBM_File. For example, by using multiple DBM implementations, you can copy a database from one format to another: use Fcntl; # for O_* values use NDBM_File; use DB_File; tie %oldhash, "NDBM_File", $old_filename, O_RDWR; tie %newhash, "DB_File", $new_filename, O_RDWR|O_CREAT|O_EXCL, 0644; while (($key,$val) = each %oldhash) { $newhash{$key} = $val; } 7.2.1.1 DBM comparisonsHere's a table of the features that the different DBMish packages offer:
7.2.1.2 See alsoRelevant library modules include: DB_File, GDBM_File, NDBM_File, ODBM_File, and SDBM_File. Related manpages: dbm(3), ndbm(3). Tied variables are discussed extensively in Chapter 5, and the dbmopen entry in Chapter 3, Functions, may also be helpful. You can pick up the unbundled modules from the src/misc/ directory on your nearest CPAN site. Here are the most popular ones, but note that their version numbers may have changed by the time you read this: http://www.perl.com/CPAN/src/misc/db.1.85.tar.gz http://www.perl.com/CPAN/src/misc/gdbm-1.7.3.tar.gz |