Q&A

Q1:Can I store the structures from Hour 13, "References and Structures," in a DBM file or a text file?
A1: The short answer is no, not easily. The longer answer is yes, but first you need to convert the "structure" over to a string that represents the data and the structure that contains it, and you then need to use that as a value in the DBM-tied hash. One module to do so is Data::Dumper.
Q2:How do I lock DBM files?
A2: DBM files can be locked using the semaphore locking system shown previously. Simply use the get_lock() and release_lock() functions from Listing 15.3 and put these around the DBM open and close functions:
 get_lock(); dbmopen(%hash, "foo", 0644) || die "dmbopen: $!"; $hash{newkey}="Value"; dbmclose(%hash); release_lock(); ...

Get Sams Teach Yourself Perl in 24 Hours 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.