Database Implementation

The example implementation uses a Perl object to hold the database. The first method defined is called new, and it creates the object.

The new function takes two parameters: the name of the database and the variable $flag is set if you want to open the database read-only. After getting the parameters, create the database using the following statement:

159      if ($flag) {
160          # The database information 
161          $database = tie (%disk_db, 
162                  'MLDBM', $db_file, 
163                  O_RDONLY, 0640); 
164          $self–>{READ_ONLY} = 1; 
165      } else {
166          # The database information 
167          $database = tie (%disk_db, 
168                  'MLDBM', $db_file, 
169                  O_RDWR|O_CREAT, 0640); 
170          $self–>{READ_ONLY} = 0; 
171      }

In this case, %disk_db contains the database data. The $database ...

Get Perl for C Programmers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.