perl-5.38.0
dbmopen HASH,DBNAME,MASK

[This function has been largely superseded by the tie function.]

[この関数は、tie 関数に 大きくとって代わられました。]

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

dbm(3), ndbm(3), sdbm(3), gdbm(3) ファイルまたは Berkeley DB ファイルを連想配列に結び付けます。 HASH は、その連想配列の名前です。 (普通の open とは違って、最初の引数は ファイルハンドル ではありません; まあ、似たようなものですが)。 DBNAME は、データベースの名前です (拡張子の .dir や .pag はもしあっても つけません)。 データベースが存在しなければ、MASK (を umask で 修正したもの) で指定されたモードで作られます。 存在しないときにデータベースを作成しないようにするには、MASK に 0 を 設定でき、データベースを見つけられなかった場合は関数は偽を返します。 古い DBM 関数のみをサポートしているシステムでは、プログラム中で 1 度だけ dbmopen を実行することができます。 昔のバージョンの Perl では、DBM も ndbm も持っていないシステムでは、 dbmopen を呼び出すと致命的エラーになります; 現在では sdbm(3) にフォールバックします。

If you don't have write access to the DBM file, you can only read hash variables, 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.

DBM ファイルに対して、書き込み権が無いときには、ハッシュ 配列を読みだすことだけができ、設定することはできません。 書けるか否かを調べたい場合には、ファイルテスト 演算子を使うか、エラーをトラップするための eval の中で、 ダミーのハッシュエントリを設定してみることになります。

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

大きな DBM ファイルを扱うときには、keysvalues のような関数は、巨大なリストを返します。 大きな DBM ファイルでは、each 関数を使って繰り返しを 行なった方が良いかもしれません。 例:

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

See also AnyDBM_File for a more general description of the pros and cons of the various dbm approaches, as well as DB_File for a particularly rich implementation.

様々な dbm 手法に対する利点欠点に関するより一般的な記述および 特にリッチな実装である DB_File に関しては AnyDBM_File も参照してください。

You can control which DBM library you use by loading that library before you call dbmopen:

dbmopen を呼び出す前にライブラリを 読み込むことで、どの DBM ライブラリを使うかを制御できます:

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

Portability issues: "dbmopen" in perlport.

移植性の問題: "dbmopen" in perlport