Cari di Perl 
    Perl User Manual
Daftar Isi
(Sebelumnya) Breaks binding on a tied dbm fileRaise an exception or bail out (Berikutnya)
Input and output functions

Create binding on a tied dbm file

Daftar Isi

  • dbmopen HASH,DBNAME,MASK

    [This function has been largely superseded by thetie function.]

    This binds a dbm(3), ndbm(3), sdbm(3), gdbm(3), or Berkeley DB file to ahash. HASH is the name of the hash. (Unlike normal open, the firstargument is not a filehandle, even though it looks like one). DBNAMEis the name of the database (without the .dir or .pag extension ifany). If the database does not exist, it is created with protectionspecified by MASK (as modified by the umask). To prevent creation ofthe database if it doesn't exist, you may specify a MODEof 0, and the function will return a false value if itcan't find an existing database. If your system supportsonly the older DBM functions, you may make only one dbmopen call in yourprogram. In older versions of Perl, if your system had neither DBM norndbm, calling dbmopen produced a fatal error; it now falls back tosdbm(3).

    If you don't have write access to the DBM file, you can only read hashvariables, not set them. If you want to test whether you can write,either use file tests or try setting a dummy hash entry inside an eval to trap the error.

    Note that functions such as keys and values may return huge listswhen used on large DBM files. You may prefer to use the eachfunction to iterate over large DBM files. Example:

    1. # print out history file offsets
    2. dbmopen(%HIST,'/usr/lib/news/history',0666);
    3. while (($key,$val) = each %HIST) {
    4. print $key, ' = ', unpack('L',$val), "\n";
    5. }
    6. dbmclose(%HIST);

    See also AnyDBM_File for a more general description of the pros andcons of the various dbm approaches, as well as DB_File for a particularlyrich implementation.

    You can control which DBM library you use by loading that librarybefore you call dbmopen():

    1. use DB_File;
    2. dbmopen(%NS_Hist, "$ENV{HOME}/.netscape/history.db")
    3. or die "Can't open netscape history file: $!";

    Portability issues: dbmopen in perlport.

 
Source : perldoc.perl.org - Official documentation for the Perl programming language
Site maintained by Jon Allen (JJ)     See the project page for more details
Documentation maintained by the Perl 5 Porters
(Sebelumnya) Breaks binding on a tied dbm fileRaise an exception or bail out (Berikutnya)