DBM stands for Database Management. Perl provides a set of built-in functions that give Perl programmers access to DBM files.
When you open a DBM file, you access it like a hash: you give it keys and it returns values, and you can add and delete key-value pairs. What's useful about DBM is that it saves the key-value data in a permanent disk file on your computer. It can thus save information between the times you run your program; it can also serve as a way to share information between different programs that need the same data. A DBM file can get very big without killing the main memory on your computer and making your program—and everything else—slow to a crawl.
There are two functions,
dbmclose, that "tie" a
hash to a DBM file; then you just use the hash. As you've seen, with
a hash, lookups are easy, as are definitions. You can get a list of all the keys
from a hash called
%my_hash by typing
%my_hash. You then can get a list of all
values by typing
values %my_hash. For large
DBM files, you may not want to do this; the Perl function
each allows you to read key-value pairs one at a
time, thus saving the memory of your running program. There is also a
delete function to remove the definitions of
entirely removes that key from the hash.
DBM files are a very simple database. They don't have the power of a relational database such as MySQL , Oracle, or PostgreSQL ; however, it's remarkable how often ...