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

9. Accessing Databases > Using DBIx::Table2Hash

Using DBIx::Table2Hash

The DBIx::Table2Hash module provides a simple way to turn a database table into a hash, turning SQL statements into simple lookups in a prepopulated table. DBIx::Table2Hash has methods to make this data available in a nested form as well as in a one-dimensional lookup table. While it doesn’t allow for updates, it provides fast, convenient access to the data of a static table, such as a table containing postal codes and the cities to which they map. For this example, assume a simple table that looks like this (using SQLite again):

CREATE TABLE postal_code (
    code VARCHAR PRIMARY KEY,
    city VARCHAR
);

Using DBIx::Table2Hash, we can get a hash of our access_log data from within Perl like so:


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

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

  

Start a Free Trial


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