You could do something like
my $placeholders = '(?,?,?)';
my $sth = $dbh->prepare("INSERT INTO $table ($fields) VALUES $placeholders");
but I guess you thought of that and your question is really
How can I get $placeholders from $fields?
If I have a variable number of fields I usually have them in array, not
a scalar, so I can just count the members:
$fields = join(',', @fields);
$placeholders = '(' . join(',', map('?', @fields)) . ')';
my $sth = $dbh->prepare("INSERT INTO $table ($fields) VALUES $placeholders");
(and then you can get rid of $fields and $placeholders and do it all in
a single line)
hp
--
_ | Peter J. Holzer | Auf jedem Computer sollte der Satz Ludwigs II
|_|_) | Sysadmin WSR | eingeprägt stehen: "Ein ewig Rätsel will ich
| | |
h...@wsr.ac.at | bleiben, mir und andern."
__/ |
http://www.hjp.at/ | -- Wolfram Heinrich in desd