Perl dbmopen Function

Advertisements


Description

This function Binds the database file specified by EXPR to the hash HASH. If the database does not exist, then it is created using the mode specified by MODE. The file EXPR should be specified without the .dir and .pag extensions. Use is now deprecated in favor of tie and one of the tied DBM hash modules, such as SDBM_File.

Syntax

Following is the simple syntax for this function:

dbmopen HASH, EXPR, MODE

Return Value

This function returns 0 on failure and 1 on success.

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

Following is the example code showing its basic usage:

#!/usr/bin/perl

# 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);

When above code is executed, it produced following result:




Advertisements
Advertisements