10.5 Conclusions

10.5  Conclusions

This Chapter has dealt with techniques that can be used to make data used within Perl programs persistent. Persistent data can be used by different runs of the same program, or by related or unrelated programs independently. We discuss three approaches for making data live even after a program that creates or manipulates them dies: DBM databases, serialization of contents of data structures, and using relational databases. Serialization produces a string from the contents of a simple or complex data structure, or an object instance. The serialized string can be stored in a file, or even in a DBM or relational database if needed. A DBM database is a simply structured two-columned database. DBM databases have been used in Unix for a long time, and are available on Windows machines and Macintoshes as well. There are various formats for DBM databases. DBM databases can be easily associated with a Perl hash. Finally,
currently available relational databases are extremely powerful and can store millions of records in tens or even hundreds of tables. Relational databases use specialized algorithms for efficient storage of and access to complex data. Perl provides an intuitive and simple two-layered interface to relational databases using the DBI.pm database-independent module and database-dependent driver modules that talk to the database directly. The DBI.pm module talks to the appropriate database driver module to communicate with the underlying database engine. Our examples have used only simple databases where one table is sufficient to store the relevant data. In realistic databases, there are usually several tables that are related using so-called foreign keys. Since a Perl program simply passes SQL queries to the appropriate database driver module, there are no complications as
far as programming goes to interact with more complex databases with many tables as long as we know how to phrase the appropriate SQL query. Whether there is one underlying table or there are many is of no concern to the Perl program. In writing programs that communicate with databases, one must remember that every vendor of databases modifies the SQL language a little bit to suit their technical or marketing objectives. This sadly means that programs may not be portable across databases since teh SQL dialects vary from database to database, sometimes in subtle manners.