NAME

DBIx::Table2Hash - Read a database table into a hash


Synopsis

        #!/usr/bin/perl
        my($key2value) = DBIx::Table2Hash -> new
        (
                dbh          => $dbh,
                table_name   => $table_name,
                key_column   => 'name',
                value_column => 'id'
        ) -> select();
        # or
        my($key2hashref) = DBIx::Table2Hash -> new
        (
                dbh          => $dbh,
                table_name   => $table_name,
                key_column   => 'name',
        ) -> select_hashref();


Description

DBIx::Table2Hash is a pure Perl module.

This module reads a database table and stores keys and values in a hash. The resultant hash is not nested in any way.

The aim is to create a hash which is a simple look-up table. To this end, the module allows the key_column to point to an SQL expression.


Distributions

This module is available both as a Unix-style distro (*.tgz) and an ActiveState-style distro (*.ppd). The latter is shipped in a *.zip file.

See http://savage.net.au/Perl-modules.html for details.

See http://savage.net.au/Perl-modules/html/installing-a-module.html for help on unpacking and installing each type of distro.


Constructor and initialization

new(...) returns a DBIx::Table2Hash object.

This is the class's contructor.

Parameters:


Method: new(...)

Returns a object of type DBIx::Table2Hash.

See above, in the section called 'Constructor and initialization'.


Method: select()

Returns a hash ref.

Calling select() actually executes the SQL select statement, and builds the hash.

Each key in the hash points to a single value.

The demo program test-table2hash.pl, in the examples/ directory, calls select().


Method: select_hashref()

Returns a hash ref.

Calling select_hashref() actually executes the SQL select statement, and builds the hash.

Each key in the hash points to a hashref.

The demo program test-table2hash.pl, in the examples/ directory, calls select_hashref().


Required Modules

Only those shipped with Perl.


Changes

See Changes.txt.


FAQ

Q: What is the point of this module?

A: To be able to restore a hash from a database rather than from a file.

Q: Can your other module DBIx::Hash2Table be used to save the hash back to the database?

A: Sure.

Q: Do you ship a complete demo, which loads a table and demonstrates the 2 methods select() and select_hashref()?

A: Yes. See the examples/ directory.

If you installed this module locally via ppm, look in the x86/ directory for the file to unpack.

If you installed this module remotely via ppm, you need to download and unpack the distro itself.

Q: Are there any other modules with similar capabilities?

A: Yes:


Author

DBIx::Table2Hash was written by Ron Savage <ron@savage.net.au> in 2003.

Home page: http://savage.net.au/index.html


Copyright

Australian copyright (c) 2003, Ron Savage. All rights reserved.

        All Programs of mine are 'OSI Certified Open Source Software';
        you can redistribute them and/or modify them under the terms of
        The Artistic License, a copy of which is available at:
        http://www.opensource.org/licenses/index.html