Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

II. Answers > R. Answers to Chapter 18 Exercises

Appendix R. Answers to Chapter 18 Exercises

Answer 18.1: The first program just needs to create the hash. Define the hash in the dbmopen function. Give the DBM file the name “birthdays” but don’t use an absolute path so dbmopen creates the file in the current directory. You may see a file extension added to the filename, and that extension depends on the particular DBM implementation on your system. In some implementations, you may even see a second, index file. As long as you use the same filename in every program (in this case, “birthdays”), you don’t need to think about how the file lives in the filesystem.

For the third parameter to dbmopen, give it a file permissions mask to use if dbmopen needs to create a file that doesn’t already exist. This number must be an octal number, so start it with a leading 0 to tell Perl that it’s a base-8 number. If you can’t open the DBM hash, use die to output an error message. You might not be able to create new files in the current working directory, for instance.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint