If we have a small amount of data, sometimes the easiest technique is to just write this data in a text file. For example, if we have a few records with a fixed number of fields we can store them in a file, having one record per row and separating the fields with a delimiter. For example:

Eric|Cholet|cholet@logilune.com
Doug|MacEachern|dougm@pobox.com
Stas|Bekman|stas@stason.org

As long as we have just a few records, we can quickly insert, edit, and remove records by reading the flat-file database line by line and adjusting things as required. We can retrieve the fields easily by using the split function:

@fields = split /\|/, $record;

and we can put them back using join:

$record = join '|', @fields;

However, we must make sure that no field uses the field separator we have chosen (| in this case), and we must lock the file if it is to be used in a multiprocess environment where many processes may try to modify the same file simultaneously. This is the case whether we are using mod_perl or not.

If we are using some flavor of Unix, the /etc/passwd file is a perfect example of a flat-file database, since it has a fixed number of fields and most systems have a relatively small number of users.[46] This is an example of such a file:

[46]Disregard the fact that the actual password is stored in /etc/shadow on modern systems.

root:x:0:0:root:/root:/bin/tcsh
bin:x:1:1:bin:/bin:
daemon:x:2:2:daemon:/sbin:
adm:x:3:4:adm:/var/adm:
lp:x:4:7:lp:/var/spool/lpd:

: is used to separate the various fields.

Working with flat-file databases is easy and straightforward in plain Perl. There are no special mod_perl tricks involved.