m{y,}sql module meisters,
The logic of one of the code examples in the DBD::mysql man page seems
to be defective.
Here's how the code looks in the manpage:
" my $sth = $dbh->prepare("SELECT * FROM $table");
if (!$sth) {
die "Error:" . $dbh->errstr . "\n";
}
if (!$sth->execute) {
die "Error:" . $sth->errstr . "\n";
}
my $names = $sth->{'NAME'};
my $numFields = $sth->{'NUM_OF_FIELDS'};
for (my $i = 0; $i < $numFields; $i++) {
printf("%s%s", $$names[$i], $i ? "," : "");
}"
Here's how I think it should look:
"my $sth = $dbh->prepare("SELECT * FROM $table");
if (!$sth) {
die "Error:" . $dbh->errstr . "\n";
}
if (!$sth->execute) {
die "Error:" . $sth->errstr . "\n";
}
my $names = $sth->{'NAME'};
my $numFields = $sth->{'NUM_OF_FIELDS'};
for( $i = $num_fields - 1; $i >= 0; $i--)
{
printf("%s%s", $$names[$i], $i ? ", " : "");
}"
The difference is in the for() loop. My way makes it add a comma and
space after all but the last field name.
--
Scott D. Webster, RHCE mailto:SWebster@stripped
Etc Services http://www.EtcServices.com
Voice: 201.439.1900 Fax: 201.439.0366 Pager: 800.379.2402
Linux, UNIX, Internet Technology,
& Open Source Software Consulting
Attachment: [application/pgp-signature]
Attachment: [application/pgp-signature]