in reply to Sql table names

I think you better explain more of the situation. Where do the table names come from? If they are part of hash, what are they associated with (filenames? connections?). What are you going to do with the table names? By hardcoded in the script, do you mean hardcoded in SQL statements? Sorry, there's not much to answer unless you can give us some clues.

Replies are listed 'Best First'.
Re^2: Sql table names
by Anonymous Monk on Aug 16, 2004 at 03:44 UTC
    My apologies, jZed, and thanks for replying.

    Each key of the hash stores the table name and the name of column to be sorted (just in case sorting is required). The table names themselves are hardcoded and do not come from an external source. However, a table may be queried for its contents by supplying its name through an online form.

    The hash I was talking about is as follows

    %table =( members => [ qw(members id) ], emails => [ qw(emails member_id)] };
    So, instead of
    SELECT * from members
    It's
    SELECT * from $table{'members'}[0]
    Does hashing the table names make sense?

    One use I could think of is verifying the table's existence when it's being queried (as in an web application).

      Now that I see what you're doing, yes, I think some kind of a hash makes sense. You wrote:
      a table may be queried for its contents by supplying its name through an online form.
      In that case, you definitely want to check the name against the hash to make sure it's a table you want users to be able to access. You may also want something like this, depending on your needs:
      my @tables = ( {name=>members,cols=>[qw(members id)]}, {name=>emails,cols=>[qw(emails member_id)]}, ); my $sql = "SELECT " . join(',',@{$tables[0]->{cols}}) . " FROM " . $tables[0]->{name} ;
      Eventually you might consider Class::DBI which provides some ready-made shortcuts for this kind of thing.