in reply to Database Table to Hash of Hash of Array

To tell you the truth, your code is horrible.

Here's a rewrite:

# "RaiseError => 1" tells DBI to die on errors. my $dbh = DBI->connect($DSN, $username, $password, { RaiseError => 1 } +); my $sth; $sth = $dbh->prepare(" SELECT table_name, column_name FROM Dba_tab_columns WHERE owner = ? ORDER BY table_name, column_name "); $sth->execute($schema); my $table_column = $sth->fetchall_arrayref; $sth->finish; for my $tcr (@{$table_column}) { if ($tcr->[0] eq "EMP") { my $sth = $dbh->prepare("SELECT " . $tcr->[1] . " FROM " . $schema + . $tcr->[0]); $sth->execute; my $column_data = $sth->fetchall_arrayref; $sth->finish; # This for-loop create a hash of a hash of an array with the keys +{table name} and {column name} for my $row (@{$column_data}) { push @{ $tables{$tcr->[0]}{$tcr->[1]} }, $row->[0]; + } } }

[ ar0n -- want job (boston) ]

Replies are listed 'Best First'.
Re: (ar0n) Re: Database Table to Hash of Hash of Array
by timo (Novice) on Dec 01, 2001 at 05:32 UTC
    Thanks alot for the feedback. I've haven't been writing Perl for very long and actually thought what I developed was pretty cool and portable to any Oracle db. I'm going to apply your comments to my code and continue to improve. Once again, thanks.