Useless use of a (constant|hash element) in void context?

ADFH mpm at bachelorguy.com
Sun Oct 5 00:38:03 CDT 2003


Basically I'm writing a generic "insert/update" function into my program
that goes and checks the table it's inserting data into for prompts as
to what kind of sanity checking it should do on the data, whether what
it thinks is the primary key is indeed the primary key, whether it
should insert or update etc. etc. etc.

To do this, I'm getting MySQL to give me output of SHOW COLUMNS on the
specific table, then wanting to store this in a hash. I then plan to
parse the data received from the end user's browser, to see if it's the
correct type, within range etc. etc. then quote/escape it appropriately.

The function is being used for several tables with varying numbers of
columns and data types. I don't forsee the script being placed under a
lot of load and at this point I don't want to duplicate similar code
with only slight alterations to check each table.

Is there something I should use that already does this? Is my thinking
flawed? Am I reinventing the wheel in regards to some DBI/DBD function I
haven't found?

Anyway, a bit of the code I'm working on gives me an error I've not seen
before. In this particular script I'm writing, I've been getting a
little more adventurous with references and functions etc. etc. and am a
bit out of my depth I think (I did some netizen courses years ago, and
have been using their doco, the camel book, cpan and the perl man pages
since).

What am I doing wrong here? I'm thinking I've just borked up some
bracket types somewhere.

        my $statement=  "SHOW COLUMNS FROM ${table_names{$table}}";
        my $sth=$dbh->prepare($statement);
        $sth->execute();
        my (%dbct, $dbr_ref);
        while ($dbr_ref=$sth->fetchrow_hashref("NAME_lc")) {
                $dbct{$dbr_ref->{'field'}}=(
                        type    =>      $dbr_ref->{'type'},
                        key     =>      $dbr_ref->{'key'},
                        blank   =>      $dbr_ref->{'null'}
                ); # Line 152
        }
        $sth->finish();

Gives warnings:

[Sun Oct  5 15:22:29 2003] index.cgi: Useless use of a constant in void context at index.cgi line 152.
[Sun Oct  5 15:22:29 2003] index.cgi: Useless use of hash element in void context at index.cgi line 152.
[Sun Oct  5 15:22:29 2003] index.cgi: Useless use of a constant in void context at index.cgi line 152.
[Sun Oct  5 15:22:29 2003] index.cgi: Useless use of hash element in void context at index.cgi line 152.
[Sun Oct  5 15:22:29 2003] index.cgi: Useless use of a constant in void context at index.cgi line 152.

Using:

MySQL 4.0.14
Perl v5.8.1 built for i386-linux-thread-multi



More information about the Melbourne-pm mailing list