Just thought I would send a bug fix on a very nice piece of code
sent by Doug Wilson - Doug's generic subroutine "insert_hash":
sub insert_hash {
my $table = shift;
my $ref = shift;
#Sort fields so we can effectively cache the statement
my @fields = sort keys %$ref;
my @values = @{$ref}{@fields};
my $sql = "insert into $table (", join(",", @fields).
") values (". join(",", ("?") x @fields).")";
my $sth = $dbh->prepare_cached($sql);
$sth->execute(@values);
}
The line that contains the "insert into $table" contains one
small but significant bug - you need to change the 1st comma
to a period(for concatenation):
From:
my $sql = "insert into $table (", join(",", @fields).
To:
my $sql = "insert into $table (". join(",", @fields).
Doug, do you have a similar "update_hash" subroutine?
Thanks.
--
Hardy Merrill
Mission Critical Linux, Inc.
http://www.missioncriticallinux.com